<!DOCTYPE html>


<html lang="en">
  

    <head>
      <meta charset="utf-8" />
        
      <meta
        name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1"
      />
      <title> 朝花夕拾</title>
  <meta name="generator" content="hexo-theme-ayer">
      
      <link rel="shortcut icon" href="/ww.ico" />
       
<link rel="stylesheet" href="/dist/main.css">

      
<link rel="stylesheet" href="/css/fonts/remixicon.css">

      
<link rel="stylesheet" href="/css/custom.css">
 
      <script src="https://cdn.staticfile.org/pace/1.2.4/pace.min.js"></script>
       
 

      <link
        rel="stylesheet"
        href="https://cdn.jsdelivr.net/npm/@sweetalert2/theme-bulma@5.0.1/bulma.min.css"
      />
      <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.19/dist/sweetalert2.min.js"></script>

      <!-- mermaid -->
      
      <style>
        .swal2-styled.swal2-confirm {
          font-size: 1.6rem;
        }
      </style>
    </head>
  </html>
</html>


<body>
  <div id="app">
    
      
    <main class="content on">
      
<section class="cover">
    
  <div class="cover-frame">
    <div class="bg-box">
      <img src="/images/cover8.jpg" alt="image frame" />
    </div>
    <div class="cover-inner text-center text-white">
      <h1><a href="/">朝花夕拾</a></h1>
      <div id="subtitle-box">
        
        <span id="subtitle"></span>
        
      </div>
      <div>
        
      </div>
    </div>
  </div>
  <div class="cover-learn-more">
    <a href="javascript:void(0)" class="anchor"><i class="ri-arrow-down-line"></i></a>
  </div>
</section>



<script src="https://cdn.staticfile.org/typed.js/2.0.12/typed.min.js"></script>


<!-- Subtitle -->

  <script>
    try {
      var typed = new Typed("#subtitle", {
        strings: ['', '', ''],
        startDelay: 0,
        typeSpeed: 200,
        loop: true,
        backSpeed: 100,
        showCursor: true
      });
    } catch (err) {
      console.log(err)
    }
  </script>
  
<div id="main">
  <section class="outer">
  
  
  

<div class="notice" style="margin-top:50px">
    <i class="ri-heart-fill"></i>
    <div class="notice-content" id="broad"></div>
</div>
<script type="text/javascript">
    fetch('https://v1.hitokoto.cn')
        .then(response => response.json())
        .then(data => {
            document.getElementById("broad").innerHTML = data.hitokoto;
        })
        .catch(console.error)
</script>

<style>
    .notice {
        padding: 20px;
        border: 1px dashed #e6e6e6;
        color: #969696;
        position: relative;
        display: inline-block;
        width: 100%;
        background: #fbfbfb50;
        border-radius: 10px;
    }

    .notice i {
        float: left;
        color: #999;
        font-size: 16px;
        padding-right: 10px;
        vertical-align: middle;
        margin-top: -2px;
    }

    .notice-content {
        display: initial;
        vertical-align: middle;
    }
</style>
  
  <article class="articles">
    
    
    
    
    <article
  id="post-GBase8s智能大对象空间满场景"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/05/10/GBase8s%E6%99%BA%E8%83%BD%E5%A4%A7%E5%AF%B9%E8%B1%A1%E7%A9%BA%E9%97%B4%E6%BB%A1%E5%9C%BA%E6%99%AF/"
    >GBase8s智能大对象空间满场景</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/05/10/GBase8s%E6%99%BA%E8%83%BD%E5%A4%A7%E5%AF%B9%E8%B1%A1%E7%A9%BA%E9%97%B4%E6%BB%A1%E5%9C%BA%E6%99%AF/" class="article-date">
  <time datetime="2023-05-10T01:21:21.000Z" itemprop="datePublished">2023-05-10</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/GBase8s/">GBase8s</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h2 id="一般大对象可以存储在blobspace上也可以和表一起存储"><a href="#一般大对象可以存储在blobspace上也可以和表一起存储" class="headerlink" title="一般大对象可以存储在blobspace上也可以和表一起存储"></a>一般大对象可以存储在blobspace上也可以和表一起存储</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> t_simple_objects(</span><br><span class="line">    id_num <span class="type">integer</span>,</span><br><span class="line">    fname <span class="type">char</span>(<span class="number">15</span>),</span><br><span class="line">    lname <span class="type">char</span>(<span class="number">15</span>), </span><br><span class="line">    vita     text, </span><br><span class="line">    photo  BYTE <span class="keyword">in</span> blobspace1 </span><br><span class="line">);  </span><br></pre></td></tr></table></figure>

<h2 id="智能大对象只能存储在sbspaces上"><a href="#智能大对象只能存储在sbspaces上" class="headerlink" title="智能大对象只能存储在sbspaces上"></a>智能大对象只能存储在sbspaces上</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> t_smart_objects  (</span><br><span class="line">    id_num <span class="type">int</span>,</span><br><span class="line">    picture <span class="type">blob</span>,</span><br><span class="line">    felony <span class="type">clob</span>  </span><br><span class="line">)PUT picture <span class="keyword">in</span>(sbspace2); </span><br></pre></td></tr></table></figure>



<h1 id="开始智能大对象的测试"><a href="#开始智能大对象的测试" class="headerlink" title="开始智能大对象的测试"></a>开始智能大对象的测试</h1><hr>
<h2 id="建表"><a href="#建表" class="headerlink" title="建表"></a>建表</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> test;</span><br><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> test (</span><br><span class="line">    oid <span class="type">int</span> ,</span><br><span class="line">    name <span class="type">varchar</span>(<span class="number">20</span>),</span><br><span class="line">    a <span class="type">clob</span>,</span><br><span class="line">    b <span class="type">char</span>(<span class="number">1</span>),</span><br><span class="line">    c <span class="type">char</span>(<span class="number">6</span>)</span><br><span class="line">);</span><br><span class="line"></span><br><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> test2;</span><br><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> test2 (</span><br><span class="line">    oid <span class="type">int</span> ,</span><br><span class="line">    name <span class="type">varchar</span>(<span class="number">20</span>),</span><br><span class="line">    a <span class="type">clob</span>,</span><br><span class="line">    b <span class="type">char</span>(<span class="number">1</span>),</span><br><span class="line">    c <span class="type">char</span>(<span class="number">6</span>)</span><br><span class="line">);</span><br></pre></td></tr></table></figure>

<h2 id="插入数据直接中之前的java插入String就行了"><a href="#插入数据直接中之前的java插入String就行了" class="headerlink" title="插入数据直接中之前的java插入String就行了"></a>插入数据直接中之前的java插入String就行了</h2><p>​		略</p>
<h2 id="智能大对象存储到了sb空间"><a href="#智能大对象存储到了sb空间" class="headerlink" title="智能大对象存储到了sb空间"></a>智能大对象存储到了sb空间</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">gbasedbt@wei66:~/d$ oncheck -pt testdb:test</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">TBLspace Report for testdb:gbasedbt.test</span><br><span class="line"></span><br><span class="line">    Physical Address               9:576</span><br><span class="line">    Creation date                  12/10/2022 18:15:54</span><br><span class="line">    TBLspace Flags                 902        Row Locking</span><br><span class="line">                                              TBLspace contains VARCHARS</span><br><span class="line">                                              TBLspace use 4 bit bit-maps</span><br><span class="line">    Maximum row size               107       </span><br><span class="line">    Number of special columns      1         </span><br><span class="line">    Number of keys                 0         </span><br><span class="line">    Number of extents              1         </span><br><span class="line">    Current serial value           1         </span><br><span class="line">    Current SERIAL8 value          1         </span><br><span class="line">    Current BIGSERIAL value        1         </span><br><span class="line">    Current REFID value            1         </span><br><span class="line">    Pagesize (k)                   2         </span><br><span class="line">    First extent size              8         </span><br><span class="line">    Next extent size               8         </span><br><span class="line">    Number of pages allocated      8         </span><br><span class="line">    Number of pages used           2         </span><br><span class="line">    Number of data pages           1         </span><br><span class="line">    Number of rows                 1         </span><br><span class="line">    Partition partnum              9437261   </span><br><span class="line">    Partition lockid               9437261   </span><br><span class="line"></span><br><span class="line">    Extents                       </span><br><span class="line">         Logical Page     Physical Page        Size Physical Pages</span><br><span class="line">                    0            9:1996           8          8</span><br><span class="line"></span><br><span class="line">gbasedbt@wei66:~/d$</span><br></pre></td></tr></table></figure>

<h3 id="sbspace01的空闲空间变少了"><a href="#sbspace01的空闲空间变少了" class="headerlink" title="sbspace01的空闲空间变少了"></a>sbspace01的空闲空间变少了</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">&gt; </span><span class="language-bash">GBase Database Server Version 12.10.FC4G1AEE -- On-Line -- Up 04:32:53 -- 930724 Kbytes</span></span><br><span class="line">27c27</span><br><span class="line">&lt; 4a18b028         8      8      0          512000     477463     477465     POSB-D /data/g300/sbspace01</span><br><span class="line">--- </span><br><span class="line"><span class="meta prompt_">&gt; </span><span class="language-bash">4a18b028         8      8      0          512000     477314     477465     POSB-D /data/g300/sbspace01</span></span><br><span class="line">  </span><br></pre></td></tr></table></figure>

<p>​			477463 - 477314   &#x3D; 149 </p>
<h3 id="SBLOBSpace-LO-8-8-1-56-149"><a href="#SBLOBSpace-LO-8-8-1-56-149" class="headerlink" title="SBLOBSpace LO [8,8,1]                                               56      149"></a>SBLOBSpace LO [8,8,1]                                               56      149</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">DBspace Usage Report: sbspace01           Owner: gbasedbt  Created: 10/27/2022</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> Chunk Pathname                             Pagesize(k)  Size(p)  Used(p)  Free(p)</span><br><span class="line">     8 /data/g300/sbspace01                           2   512000 see below see below</span><br><span class="line"></span><br><span class="line"> Description                                                   Offset(p)  Size(p)</span><br><span class="line"> ------------------------------------------------------------- -------- --------</span><br><span class="line"> RESERVED PAGES                                                       0        2</span><br><span class="line"> CHUNK FREELIST PAGE                                                  2        1</span><br><span class="line"> sbspace01:&#x27;gbasedbt&#x27;.TBLSpace                                        3       50</span><br><span class="line"> SBLOBSpace FREE USER DATA (AREA 1)                                  53        1</span><br><span class="line"> SBLOBSpace LO [8,8,2]                                               54        1</span><br><span class="line"> SBLOBSpace LO [8,8,3]                                               55        1</span><br><span class="line"> SBLOBSpace LO [8,8,1]                                               56      149</span><br><span class="line"> SBLOBSpace FREE USER DATA (AREA 1)                                 205   136192</span><br><span class="line"> SBLOBSpace RESERVED USER DATA (AREA 1)                          136397   102388</span><br><span class="line"> sbspace01:&#x27;gbasedbt&#x27;.sbspace_desc                               238785        4</span><br><span class="line"> sbspace01:&#x27;gbasedbt&#x27;.chunk_adjunc                               238789        4</span><br><span class="line"> sbspace01:&#x27;gbasedbt&#x27;.LO_ud_free                                 238793     1326</span><br><span class="line"> sbspace01:&#x27;gbasedbt&#x27;.LO_hdr_partn                               240119     7489</span><br><span class="line"> SBLOBSpace FREE META DATA                                       247608    25659</span><br><span class="line"> SBLOBSpace RESERVED USER DATA (AREA 2)                          273267   102388</span><br><span class="line"> SBLOBSpace FREE USER DATA (AREA 2)                              375655   136345</span><br><span class="line"></span><br><span class="line"> Total Used:     9027</span><br><span class="line"> Total SBLOBSpace FREE META DATA:    25659</span><br><span class="line"> Total SBLOBSpace FREE USER DATA:   477314</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h1 id="调整一下大对象大小和insert行数"><a href="#调整一下大对象大小和insert行数" class="headerlink" title="调整一下大对象大小和insert行数"></a>调整一下大对象大小和insert行数</h1><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@GetMapping(&quot;/insertTest&quot;)</span></span><br><span class="line"><span class="keyword">public</span> String <span class="title function_">insertTest</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">String</span> <span class="variable">str</span> <span class="operator">=</span> <span class="string">&quot;&quot;</span>;</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">int</span> i=<span class="number">1</span>; i&lt;<span class="number">1000</span>;i++)&#123;</span><br><span class="line">        str = str+<span class="string">&quot;中&quot;</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">int</span> i=<span class="number">1</span>; i&lt;<span class="number">1000</span>;i++)&#123;</span><br><span class="line">        testMapper.insertTest(<span class="keyword">new</span> <span class="title class_">Test</span>(<span class="number">2</span>,<span class="string">&quot;中国&quot;</span>,str,<span class="string">&quot;a&quot;</span>,<span class="string">&quot;中国&quot;</span>));</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="string">&quot;insert ok&quot;</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h1 id="智能大对象空间满了"><a href="#智能大对象空间满了" class="headerlink" title="智能大对象空间满了"></a>智能大对象空间满了</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">gbasedbt@wei66:~$ onstat -d</span><br><span class="line"></span><br><span class="line">GBase Database Server Version 12.10.FC4G1AEE -- On-Line -- Up 04:38:08 -- 930724 Kbytes</span><br><span class="line"></span><br><span class="line">Dbspaces</span><br><span class="line">address          number   flags      fchunk   nchunks  pgsize   flags    owner    name</span><br><span class="line">4737f028         1        0x40001    1        1        2048     N  BA    gbasedbt rootdbs</span><br><span class="line">49f7ddc8         2        0x40001    2        1        2048     N  BA    gbasedbt plogdbs</span><br><span class="line">4a173028         3        0x40001    3        1        2048     N  BA    gbasedbt llogdbs</span><br><span class="line">4a173258         4        0x42001    4        1        2048     N TBA    gbasedbt tempdbs01</span><br><span class="line">4a173488         5        0x42001    5        1        2048     N TBA    gbasedbt tempdbs02</span><br><span class="line">4a1736b8         6        0x42001    6        1        2048     N TBA    gbasedbt tempdbs03</span><br><span class="line">4a1738e8         7        0x42001    7        1        2048     N TBA    gbasedbt tempdbs04</span><br><span class="line">4a173b18         8        0x48001    8        1        2048     N SBA    gbasedbt sbspace01</span><br><span class="line">4a173d48         9        0x40001    9        1        2048     N  BA    gbasedbt datadbs01</span><br><span class="line">4a174028         10       0x40001    10       1        16384    N  BA    gbasedbt datadbs02</span><br><span class="line"> 10 active, 2047 maximum</span><br><span class="line"></span><br><span class="line">Chunks</span><br><span class="line">address          chunk/dbs     offset     size       free       bpages     flags pathname</span><br><span class="line">4737f258         1      1      0          512000     499549                PO-B-D /data/g300/rootchk</span><br><span class="line">4a174258         2      2      0          512000     11947                 PO-B-D /data/g300/plogchk</span><br><span class="line">4a175028         3      3      0          512000     11947                 PO-B-D /data/g300/llogchk</span><br><span class="line">4a176028         4      4      0          512000     511947                PO-B-- /data/g300/tempchk01</span><br><span class="line">4a177028         5      5      0          512000     511947                PO-B-- /data/g300/tempchk02</span><br><span class="line">4a178028         6      6      0          512000     511947                PO-BE- /data/g300/tempchk03</span><br><span class="line">4a179028         7      7      0          512000     511947                PO-B-- /data/g300/tempchk04</span><br><span class="line">4a17a028         8      8      0          512000     0          451868     POSB-D /data/g300/sbspace01</span><br><span class="line">                                 Metadata 60079      0          60079   </span><br><span class="line">4a17b028         9      9      0          512000     497652                PO-B-D /data/g300/datachk01</span><br><span class="line">4a17c028         10     10     0          6400       5821                  PO-B-D /data/g300/datachk02</span><br><span class="line"> 10 active, 32766 maximum</span><br><span class="line"></span><br><span class="line">NOTE: The values in the &quot;size&quot; and &quot;free&quot; columns for DBspace chunks are</span><br><span class="line">      displayed in terms of &quot;pgsize&quot; of the DBspace to which they belong.</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">Expanded chunk capacity mode: always</span><br><span class="line"></span><br><span class="line">gbasedbt@wei66:~$ </span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br></pre></td><td class="code"><pre><span class="line">gbasedbt@wei66:~$ onstat -g smb</span><br><span class="line"></span><br><span class="line">Smart Blob Usage:</span><br><span class="line"></span><br><span class="line">  onstat -g smb [c | s]</span><br><span class="line">                [e | h] [cad | fdd | lod]</span><br><span class="line"></span><br><span class="line">  c          chunks in the sbspace</span><br><span class="line">  e          entries in all smart-large-object table types</span><br><span class="line">  cad        smart-large-object chunk adjunct table</span><br><span class="line">  fdd        smart-large-object file descriptors</span><br><span class="line">  lod        smart-large-object header table</span><br><span class="line">  s          sbspace attributes</span><br><span class="line">  h          headers of all smart-large-object table types</span><br><span class="line"></span><br><span class="line">gbasedbt@wei66:~$ </span><br><span class="line">gbasedbt@wei66:~$ </span><br><span class="line">gbasedbt@wei66:~$ onstat -g smb c</span><br><span class="line"></span><br><span class="line">GBase Database Server Version 12.10.FC4G1AEE -- On-Line -- Up 04:42:02 -- 930724 Kbytes</span><br><span class="line"></span><br><span class="line">Chunk Summary:</span><br><span class="line"></span><br><span class="line">sbnum 8    chunk 8   </span><br><span class="line">    Chunk: address          flags    offset   size     orig fr  usr pgs  free pg</span><br><span class="line">                   4a17a028 F------- 0        512000   451868   451868   0       </span><br><span class="line">           path: /data/g300/sbspace01</span><br><span class="line"></span><br><span class="line">           start pg npages </span><br><span class="line">    Ud1  : 53       213135  </span><br><span class="line">    Md   : 213188   60079   </span><br><span class="line">    Ud2  : 273267   238733  </span><br><span class="line"></span><br><span class="line"></span><br><span class="line">gbasedbt@wei66:~$ onstat -g smb e</span><br><span class="line"></span><br><span class="line">GBase Database Server Version 12.10.FC4G1AEE -- On-Line -- Up 04:42:08 -- 930724 Kbytes</span><br><span class="line"></span><br><span class="line">Lo Header Table Entries</span><br><span class="line"></span><br><span class="line"> opns refs       size  ha_status   h_status [sbs,chk,seq(rid),oid] address, lsn to wait for(Mach11 only)</span><br><span class="line"></span><br><span class="line">Lofd Table Entries - Transaction Information</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">gbasedbt@wei66:~$ onstat -g smb cad</span><br><span class="line"></span><br><span class="line">GBase Database Server Version 12.10.FC4G1AEE -- On-Line -- Up 04:42:17 -- 930724 Kbytes</span><br><span class="line"></span><br><span class="line">gbasedbt@wei66:~$ onstat -g smb fdd</span><br><span class="line"></span><br><span class="line">GBase Database Server Version 12.10.FC4G1AEE -- On-Line -- Up 04:42:28 -- 930724 Kbytes</span><br><span class="line"></span><br><span class="line">Lofd Table Entries - Transaction Information</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">gbasedbt@wei66:~$ onstat -g smb lod</span><br><span class="line"></span><br><span class="line">GBase Database Server Version 12.10.FC4G1AEE -- On-Line -- Up 04:42:39 -- 930724 Kbytes</span><br><span class="line"></span><br><span class="line">Lo Header Table Header</span><br><span class="line"></span><br><span class="line">Table_Name   Flags      # Primary  # Sec.     Entry_Size Capacity</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">Buckets    <span class="comment"># Heads    # Entries  # Extends  # Reused</span></span></span><br><span class="line">------------ ---------- ---------- ---------- ---------- ----------</span><br><span class="line"> sb_loheader       0x5c        512         80        516         80</span><br><span class="line">         512        409          1          0          0</span><br><span class="line"></span><br><span class="line">Lo Header Table Entries</span><br><span class="line"></span><br><span class="line"> opns refs       size  ha_status   h_status [sbs,chk,seq(rid),oid] address, lsn to wait for(Mach11 only)</span><br><span class="line"></span><br><span class="line">gbasedbt@wei66:~$ onstat -g smb s</span><br><span class="line"></span><br><span class="line">GBase Database Server Version 12.10.FC4G1AEE -- On-Line -- Up 04:43:07 -- 930724 Kbytes</span><br><span class="line"></span><br><span class="line">Sbspace Summary:</span><br><span class="line"></span><br><span class="line">sbnum 8    address 4a173b18</span><br><span class="line">    Space    : flags    nchk     owner    sbname  </span><br><span class="line">               -------- 1        gbasedbt sbspace01         </span><br><span class="line">    Defaults : </span><br><span class="line">               </span><br><span class="line">    LO       : ud b/pg  flags    flags    avg s/kb max lcks</span><br><span class="line">               2048     0        -------- -1       -1      </span><br><span class="line">    Ext/IO   : 1st sz/p nxt sz/p min sz/p mx io sz</span><br><span class="line">               0        0        0        -1      </span><br><span class="line"></span><br><span class="line">    HdrCache : max      free</span><br><span class="line">               512      1       </span><br><span class="line"></span><br><span class="line">gbasedbt@wei66:~$ onstat -g smb h</span><br><span class="line"></span><br><span class="line">GBase Database Server Version 12.10.FC4G1AEE -- On-Line -- Up 04:43:24 -- 930724 Kbytes</span><br><span class="line"></span><br><span class="line">Lo Header Table Header</span><br><span class="line"></span><br><span class="line">Table_Name   Flags      # Primary  # Sec.     Entry_Size Capacity</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">Buckets    <span class="comment"># Heads    # Entries  # Extends  # Reused</span></span></span><br><span class="line">------------ ---------- ---------- ---------- ---------- ----------</span><br><span class="line"> sb_loheader       0x5c        512         80        516         80</span><br><span class="line">         512        409          1          0          0</span><br><span class="line"></span><br><span class="line">gbasedbt@wei66:~$ </span><br></pre></td></tr></table></figure>



<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">9:37:16  Logical Log 23 - Backup Started</span><br><span class="line">19:37:35  Logical Log 23 - Backup Completed</span><br><span class="line">19:37:35  Process exited with return code 127: /bin/sh /bin/sh -c /opt/install/g300/etc/alarmprogram.sh 2 18 &quot;Log Backup completed: 23.&quot; &quot;Logical Log 23 - Backup Completed&quot; &quot;&quot; 18001</span><br><span class="line">19:37:57  Freeing reserve space from chunk 8 to Userdata </span><br><span class="line">19:37:57  Allocated 51194 pages to Userdata from chunk 8</span><br><span class="line">19:39:49  Checkpoint Completed:  duration was 4 seconds.</span><br><span class="line"></span><br><span class="line">19:41:12  WARNING: sbspace sbspace01 is full</span><br><span class="line">19:41:13  Process exited with return code 127: /bin/sh /bin/sh -c /opt/install/g300/etc/alarmprogram.sh 3 44 &quot;DBSpace is full: &#x27;sbspace01&#x27;&quot; &quot;WARNING: sbspace sbspace01 is full&quot; &quot;&quot; 44001</span><br><span class="line">19:44:52  Checkpoint Completed:  duration was 3 seconds.</span><br></pre></td></tr></table></figure>

 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%A4%A7%E5%AF%B9%E8%B1%A1/" rel="tag">大对象</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%B5%8B%E8%AF%95%E7%94%A8%E4%BE%8B/" rel="tag">测试用例</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
    <article
  id="post-GBase8s如何配置审计功能"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/05/10/GBase8s%E5%A6%82%E4%BD%95%E9%85%8D%E7%BD%AE%E5%AE%A1%E8%AE%A1%E5%8A%9F%E8%83%BD/"
    >GBase8s如何配置审计功能</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/05/10/GBase8s%E5%A6%82%E4%BD%95%E9%85%8D%E7%BD%AE%E5%AE%A1%E8%AE%A1%E5%8A%9F%E8%83%BD/" class="article-date">
  <time datetime="2023-05-10T01:16:17.000Z" itemprop="datePublished">2023-05-10</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/GBase8s/">GBase8s</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h1 id="关于GBase8s如何配置审计功能"><a href="#关于GBase8s如何配置审计功能" class="headerlink" title="关于GBase8s如何配置审计功能"></a>关于GBase8s如何配置审计功能</h1><h2 id="1、配置审计："><a href="#1、配置审计：" class="headerlink" title="1、配置审计："></a>1、配置审计：</h2><p>a、通过gbasedbt用户登录操作系统，执行</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mkdir <span class="operator">~</span><span class="operator">/</span>audit_log</span><br></pre></td></tr></table></figure>

<p>b、指定审计文件路径为&#x2F;opt&#x2F;gbase8s&#x2F;audit_log，大小256MB</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">onaudit <span class="operator">-</span>p <span class="operator">~</span><span class="operator">/</span>audit_log <span class="operator">-</span>s <span class="number">256000000</span></span><br></pre></td></tr></table></figure>

<p>c、指定用户缺省下需要审计的事件（访问数据表，更新数据行，删除数据行，插入数据行）</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">onaudit <span class="operator">-</span>a <span class="operator">-</span>u _default <span class="operator">-</span>e <span class="operator">+</span>ACTB,UPRW,DLRW,INRW</span><br></pre></td></tr></table></figure>

<p>查看审计事件：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">onaudit <span class="operator">-</span>o <span class="operator">-</span>u _default</span><br></pre></td></tr></table></figure>

<p>修改掩码（+表示添加，-表示删除）</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">onaudit <span class="operator">-</span>m <span class="operator">-</span>u _default <span class="operator">-</span>e <span class="operator">+</span>DLRW,INRW,CRTB, <span class="operator">-</span>e <span class="operator">-</span>ACTB</span><br></pre></td></tr></table></figure>

<p>删除审计事件</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">onaudit <span class="operator">-</span>d <span class="operator">-</span>u _default</span><br></pre></td></tr></table></figure>

<p>d、打开按行审计模式(细粒度审计)</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">onaudit <span class="operator">-</span>R <span class="number">0</span></span><br></pre></td></tr></table></figure>

<h2 id="2、启用审计："><a href="#2、启用审计：" class="headerlink" title="2、启用审计："></a>2、启用审计：</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">onaudit <span class="operator">-</span>l <span class="number">1</span></span><br></pre></td></tr></table></figure>

<h2 id="3、启用审计后输出至日志："><a href="#3、启用审计后输出至日志：" class="headerlink" title="3、启用审计后输出至日志："></a>3、启用审计后输出至日志：</h2><p>a、通过gbasedbt用户登录操作系统并连接数据库实例，执行</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dbaccess <span class="operator">-</span> <span class="operator">-</span></span><br></pre></td></tr></table></figure>

<p>b、执行数据库操作，在数据库操作符下执行：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> database testaudit;</span><br><span class="line">database testaudit;</span><br><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> testtable(id <span class="type">int</span>,subject <span class="type">varchar</span>(<span class="number">20</span>));</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> testtable  <span class="keyword">values</span> (<span class="number">1</span>,<span class="string">&#x27;insert data&#x27;</span>);                     </span><br><span class="line"><span class="keyword">update</span> testtable <span class="keyword">set</span> subject<span class="operator">=</span><span class="string">&#x27;update data&#x27;</span> <span class="keyword">where</span> id<span class="operator">=</span><span class="number">1</span>;</span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> testtable;</span><br><span class="line"><span class="keyword">delete</span> <span class="keyword">from</span> testtable;</span><br><span class="line">database sysadmin;</span><br><span class="line"><span class="keyword">drop</span> database testaudit;</span><br></pre></td></tr></table></figure>

<p>c、浏览审计日志，在系统提示符下执行：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">onshowaudit <span class="operator">-</span>f <span class="operator">~</span><span class="operator">/</span>audit_log<span class="operator">/</span>ol_gbase8s<span class="number">.0</span> </span><br></pre></td></tr></table></figure>

<h2 id="4、关闭审计"><a href="#4、关闭审计" class="headerlink" title="4、关闭审计"></a>4、关闭审计</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">onaudit <span class="operator">-</span>l <span class="number">0</span></span><br></pre></td></tr></table></figure>

<h2 id="5、关闭审计后审计日志输出"><a href="#5、关闭审计后审计日志输出" class="headerlink" title="5、关闭审计后审计日志输出"></a>5、关闭审计后审计日志输出</h2><p>a、通过gbasedbt用户登录操作系统并连接数据库实例，执行</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dbaccess <span class="operator">-</span> <span class="operator">-</span></span><br></pre></td></tr></table></figure>

<p>b、执行数据库操作，在数据库操作符下执行：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> database testaudit;</span><br><span class="line">database testaudit;</span><br><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> testtable(id <span class="type">int</span>,subject <span class="type">varchar</span>(<span class="number">20</span>));</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> testtable <span class="keyword">values</span> (<span class="number">1</span>,<span class="string">&#x27;insert data&#x27;</span>);                     </span><br><span class="line"><span class="keyword">update</span> testtable <span class="keyword">set</span> subject<span class="operator">=</span><span class="string">&#x27;update data&#x27;</span> <span class="keyword">where</span> id<span class="operator">=</span><span class="number">1</span>;</span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> testtable;</span><br><span class="line"><span class="keyword">delete</span> <span class="keyword">from</span> testtable;</span><br><span class="line">database sysadmin;</span><br><span class="line"><span class="keyword">drop</span> database testaudit;</span><br></pre></td></tr></table></figure>

<p>c、浏览审计日志，在系统提示符下执行：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">onshowaudit <span class="operator">-</span>f <span class="operator">/</span>opt<span class="operator">/</span>gbase8s<span class="operator">/</span>audit_log<span class="operator">/</span>ol_gbase8s<span class="number">.0</span></span><br></pre></td></tr></table></figure>







<hr>
<h1 id="知识扩展"><a href="#知识扩展" class="headerlink" title="知识扩展"></a>知识扩展</h1><h2 id="检查审计配置"><a href="#检查审计配置" class="headerlink" title="检查审计配置"></a>检查审计配置</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">gbasedbt@wei66:~$ onaudit -c</span><br><span class="line">Onaudit -- Audit Subsystem Configuration Utility</span><br><span class="line"></span><br><span class="line">Current audit system configuration:</span><br><span class="line">    ADTMODE    = 0</span><br><span class="line">    ADTERR     = 0</span><br><span class="line">    ADTPATH    = /home/gbasedbt/audit_log</span><br><span class="line">    ADTSIZE    = 256000000</span><br><span class="line">    Audit file = 0</span><br><span class="line">    ADTROWS    = 0</span><br><span class="line">gbasedbt@wei66:~$ </span><br></pre></td></tr></table></figure>

<h3 id="ADTMODE-审计级别"><a href="#ADTMODE-审计级别" class="headerlink" title="ADTMODE 审计级别"></a>ADTMODE 审计级别</h3><p>onaudit -l 1</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">要开始审计所有会话，需输入 $ onaudit -l 1。以下是附加审计级别选项：</span><br><span class="line">0 = 禁用审计</span><br><span class="line">1 = 启用审计，审计所有会话</span><br><span class="line">3 = 启用审计，审计 DBSSO 操作</span><br><span class="line">5 = 启用审计，审计数据库服务器管理员操作</span><br><span class="line">7 = 启用审计，审计 DBSSO 及数据库服务器管理员操作</span><br></pre></td></tr></table></figure>

<h3 id="ADTERR"><a href="#ADTERR" class="headerlink" title="ADTERR"></a>ADTERR</h3><p>onaudit -e 0 </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">0 =继续错误模式</span><br><span class="line">1 = halt错误模式:暂停线程处理</span><br><span class="line">3 = halt error mode:关闭系统</span><br></pre></td></tr></table></figure>

<h3 id="ADTPATH"><a href="#ADTPATH" class="headerlink" title="ADTPATH"></a>ADTPATH</h3><p>审计日志存储路径。通过 -p可以设置。</p>
<h3 id="ADTSIZE"><a href="#ADTSIZE" class="headerlink" title="ADTSIZE"></a>ADTSIZE</h3><p>单个审计文件的大小，单位是字节。通过 -s可以设置。</p>
<h3 id="Audit-file"><a href="#Audit-file" class="headerlink" title="Audit file"></a>Audit file</h3><p>是审计文件的下标，用onaudit -n 切换一个，这个Audit fIle 就会加1.</p>
<h3 id="ADTROWS"><a href="#ADTROWS" class="headerlink" title="ADTROWS"></a>ADTROWS</h3><p>onaudit -R 1 </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">行审计 Options: </span><br><span class="line">0 = Auditing row-level events on all tables (0 is the default value) </span><br><span class="line">1 = Selective row-level auditing is enabled for tables set with the AUDIT flag. </span><br><span class="line">2 = Selective row-level auditing is enabled for tables set with the AUDIT flag.</span><br><span class="line"></span><br><span class="line">翻译：</span><br><span class="line">0 =审计所有表上的行级事件(0是默认值)</span><br><span class="line">1 =对带有AUDIT标志的表启用选择性行级审计。</span><br><span class="line">2 =对带有AUDIT标志的表启用选择性行级审计。</span><br></pre></td></tr></table></figure>



<h1 id="查看审计文件"><a href="#查看审计文件" class="headerlink" title="查看审计文件"></a>查看审计文件</h1><p>审计文件后面的三个字段，分别是 tid，partnum，rowid</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">gbasedbt@wei66:~/audit_log$ tail g300.3 </span><br><span class="line">ONLN|2022-12-11 16:41:02.000|localhost|24531|g300|gbasedbt|0:UPRW:sysmaster:226:1025:0:1025:256::</span><br><span class="line">ONLN|2022-12-11 16:41:02.000|localhost|24531|g300|gbasedbt|0:ACTB:sysmaster:gbasedbt:syscrtadt:227</span><br><span class="line">ONLN|2022-12-11 16:41:02.000|localhost|24531|g300|gbasedbt|0:INRW:sysmaster:227:1026:11010::</span><br><span class="line">ONLN|2022-12-11 16:41:19.000|localhost|24536|g300|gbasedbt|0:ACTB:sysmaster:gbasedbt:sysadtinfo:226</span><br><span class="line">ONLN|2022-12-11 16:41:19.000|localhost|24536|g300|gbasedbt|0:ACTB:sysmaster:gbasedbt:sysadtinfo:226</span><br><span class="line">ONLN|2022-12-11 16:41:19.000|localhost|24536|g300|gbasedbt|0:ACTB:sysmaster:gbasedbt:syscrtadt:227</span><br><span class="line">ONLN|2022-12-11 16:41:19.000|localhost|24536|g300|gbasedbt|0:INRW:sysmaster:227:1026:11010::</span><br><span class="line">ONLN|2022-12-11 16:42:45.000|localhost|24537|g300|gbasedbt|0:ACTB:sysmaster:gbasedbt:sysadtinfo:226</span><br><span class="line">ONLN|2022-12-11 16:42:45.000|localhost|24537|g300|gbasedbt|0:ACTB:sysmaster:gbasedbt:sysadtinfo:226</span><br><span class="line">gbasedbt@wei66:~/audit_log$ </span><br><span class="line">gbasedbt@wei66:~/audit_log$ </span><br><span class="line">gbasedbt@wei66:~/audit_log$ tail g300.10</span><br><span class="line">ONLN|2022-12-11 16:49:10.000|localhost|24617|g300|gbasedbt|0:DLRW:testdb:114:9437261:2081556::</span><br><span class="line">ONLN|2022-12-11 16:49:10.000|localhost|24617|g300|gbasedbt|0:DLRW:testdb:114:9437261:2081793::</span><br><span class="line">ONLN|2022-12-11 16:49:10.000|localhost|24617|g300|gbasedbt|0:DLRW:testdb:114:9437261:2081794::</span><br><span class="line">ONLN|2022-12-11 16:49:10.000|localhost|24617|g300|gbasedbt|0:DLRW:testdb:114:9437261:2081795::</span><br><span class="line">ONLN|2022-12-11 16:49:10.000|localhost|24617|g300|gbasedbt|0:DLRW:testdb:114:9437261:2081796::</span><br><span class="line">ONLN|2022-12-11 16:49:10.000|localhost|24617|g300|gbasedbt|0:DLRW:testdb:114:9437261:2081797::</span><br><span class="line">ONLN|2022-12-11 16:49:10.000|localhost|24617|g300|gbasedbt|0:DLRW:testdb:114:9437261:2081798::</span><br><span class="line">ONLN|2022-12-11 16:49:10.000|localhost|24617|g300|gbasedbt|0:DLRW:testdb:114:9437261:2081799::</span><br><span class="line">ONLN|2022-12-11 16:49:10.000|localhost|24617|g300|gbasedbt|0:DLRW:testdb:114:9437261:2081800::</span><br><span class="line">ONLN|2022-12-11 16:49:10.000|localhost|24617|g300|gbasedbt|0:DLRW:testdb:114:9437261:2081801::</span><br><span class="line">gbasedbt@wei66:~/audit_log$ </span><br></pre></td></tr></table></figure>





<h1 id="审计掩码"><a href="#审计掩码" class="headerlink" title="审计掩码"></a>审计掩码</h1><p><a target="_blank" rel="noopener" href="https://www.ibm.com/docs/en/informix-servers/12.10?topic=analysis-audit-record-format">https://www.ibm.com/docs/en/informix-servers/12.10?topic=analysis-audit-record-format</a></p>
<p><a target="_blank" rel="noopener" href="https://www.ibm.com/docs/en/informix-servers/12.10?topic=security-audit-event-codes-fields#ids_au_104">https://www.ibm.com/docs/en/informix-servers/12.10?topic=security-audit-event-codes-fields#ids_au_104</a></p>
<table>
<thead>
<tr>
<th>Event Code</th>
<th>Event</th>
<th>Variable Contents</th>
</tr>
</thead>
<tbody><tr>
<td>ACTB</td>
<td>Access Table</td>
<td>dbname: database_nametabid: owner_name, table_id</td>
</tr>
<tr>
<td>ADCK</td>
<td>Add Chunk</td>
<td>dbname: dbspace, nameextra_1: offset flags: mirror_status1 extra_2: path and size</td>
</tr>
<tr>
<td>ADLG</td>
<td>Add Transaction Log</td>
<td>dbname: dbspace, nameextra_1: log_size</td>
</tr>
<tr>
<td>ALFR</td>
<td>Alter Fragement</td>
<td>dbname: database_nametabid: table_id objname: index_name extra_1: operation_type18 login: owner flags: frag_flags15 extra_2: dbspaces alter_type: 0 &#x3D; normal, 1 &#x3D; forced alter</td>
</tr>
<tr>
<td>ALIX</td>
<td>Alter Index</td>
<td>dbname: database_nametabid: table_id login: owner14 flags: cluster_flag9,14 extra_2: index_name14</td>
</tr>
<tr>
<td>ALLC</td>
<td>Alter Security Label Component</td>
<td>dbname: database_nameobjname: component_name extra_2: component_type</td>
</tr>
<tr>
<td>ALME</td>
<td>Alter Access Method</td>
<td>dbname: database_nametabid: access, method_ID objname: access_method, name login: access_method, owner</td>
</tr>
<tr>
<td>ALOC</td>
<td>Alter Operator Class</td>
<td>dbname: database_nameextra_1: cluster_size login: owner extra_2: cluster_name</td>
</tr>
<tr>
<td>ALSQ</td>
<td>Alter Sequence</td>
<td>dbname: database_nametabid: table_id</td>
</tr>
<tr>
<td>ALTB</td>
<td>Alter Table</td>
<td>dbname: database_nametabid: old_table_id extra_1: new_table_id14 partno: frag_id extra_2: new_part_number_list14</td>
</tr>
<tr>
<td>ALTX</td>
<td>Alter trusted context</td>
<td>dbname: database_nameobjname: context_name login: system_authid</td>
</tr>
<tr>
<td>ALUR</td>
<td>Alter User</td>
<td>objname: user_name</td>
</tr>
<tr>
<td>BGTX</td>
<td>Begin Transaction</td>
<td>none</td>
</tr>
<tr>
<td>CLDB</td>
<td>Close Database</td>
<td>dbname: database_name</td>
</tr>
<tr>
<td>CMTX</td>
<td>Commit Transaction</td>
<td>none</td>
</tr>
<tr>
<td>CRAG</td>
<td>Create Aggregate</td>
<td>dbname: database_nameobjname: aggregate_name login: owner</td>
</tr>
<tr>
<td>CRAM</td>
<td>Create Audit Mask</td>
<td>login: user_id</td>
</tr>
<tr>
<td>CRBS</td>
<td>Create Storage Space</td>
<td>dbname: storage_name, space_namelogin: owner flags: mirror_status1 extra_2: media</td>
</tr>
<tr>
<td>CRBT</td>
<td>Create Opaque Type</td>
<td>dbname: database_nameobjname: opaque_type_name login: opaque_type, owner</td>
</tr>
<tr>
<td>CRCT</td>
<td>Create Cast</td>
<td>dbname: database_nametabid: from_type_ID objname: function_name or “-“ extra_1: from_type_xid partno: to_type_ID row_num: to_type_xid login: function_owner or “-“</td>
</tr>
<tr>
<td>CRDB</td>
<td>Create Database</td>
<td>dbname: dbspaceextra_2: database_name</td>
</tr>
<tr>
<td>CRDS</td>
<td>Create Dbspace</td>
<td>dbname: dbspace, nameflags: mirror_status1</td>
</tr>
<tr>
<td>CRDT</td>
<td>Create Distinct Type</td>
<td>dbname: database_nameobjname: distinct_type_name login: distinct_type, owner</td>
</tr>
<tr>
<td>CRIX</td>
<td>Create Index</td>
<td>dbname: database_nametabid: table_id objname: index_name login: owner flags: frag_flags15 extra_2: dbspace_list</td>
</tr>
<tr>
<td>CRLB</td>
<td>Create Security Label</td>
<td>dbname: database_nameobjname: policy.label_name</td>
</tr>
<tr>
<td>CRLC</td>
<td>Create Security Label Component</td>
<td>dbname: database_nameobjname: component_name</td>
</tr>
<tr>
<td>CRME</td>
<td>Create Access Method</td>
<td>dbname: database_nametabid: access_method_ID objname: access_method_name login: access_method_owner</td>
</tr>
<tr>
<td>CROC</td>
<td>Create Operator Class</td>
<td>dbname: database_nametabid: operator_class_ID objname: operator_class_name login: owner</td>
</tr>
<tr>
<td>CRPL</td>
<td>Create Security Policy</td>
<td>dbname: database_nameobjname: policy_name</td>
</tr>
<tr>
<td>CRPT</td>
<td>Decryption Failure or Attempt</td>
<td>dbname: database_nameobjname: statement</td>
</tr>
<tr>
<td>CRRL</td>
<td>Create Role</td>
<td>dbname: database_nameobjname: rolename</td>
</tr>
<tr>
<td>CRRT</td>
<td>Create Named Row Type</td>
<td>dbname: database_nametabid: row_type_xid objname: named_row_type_name login: named_row_type_owner</td>
</tr>
<tr>
<td>CRSN</td>
<td>Create Synonym</td>
<td>dbname: database_nametabid: synonym_table_id extra_1: base_table_id login: owner flags: synonym_type7 extra_2: synonym_name</td>
</tr>
<tr>
<td>CRSP</td>
<td>Create SPL Routine</td>
<td>dbname: database_nametabid: proc_id login: owner extra_2: procedure_name</td>
</tr>
<tr>
<td>CRSQ</td>
<td>Create Sequence</td>
<td>dbname: database_nametabid: table_id objname: owner</td>
</tr>
<tr>
<td>CRTB</td>
<td>Create Table</td>
<td>dbname: database_nametabid: table_id objname: owner login: table_name flags: frag_flags15 extra_2: dbspace_list</td>
</tr>
<tr>
<td>CRTR</td>
<td>Create Trigger</td>
<td>dbname: database_nametabid: table_id row_num: trigger_id14 login: owner14 extra_2: trigger_name14</td>
</tr>
<tr>
<td>CRTX</td>
<td>Create trusted context</td>
<td>dbname: database_nameobjname: context_name login: system_authorization_id</td>
</tr>
<tr>
<td>CRUR</td>
<td>Create User</td>
<td>objname: user_name</td>
</tr>
<tr>
<td>CRVW</td>
<td>Create View</td>
<td>dbname: database_nametabid: view_table_id login: owner extra_2: view_name</td>
</tr>
<tr>
<td>CRXD</td>
<td>Create XADatasource</td>
<td>dbname: database_nameobjname: owner objname: XA_data_source_name</td>
</tr>
<tr>
<td>CRXT</td>
<td>Create XADatasource Type</td>
<td>dbname: database_nameobjname: owner objname: XA_data_source_type_name</td>
</tr>
<tr>
<td>DLRW</td>
<td>Delete Row</td>
<td>dbname: database_nametabid: table_id extra_1: part_number partno: frag_id row_num: row_number14</td>
</tr>
<tr>
<td>DNCK</td>
<td>Bring Chunk Offline</td>
<td>extra_1: chunk_numberflags: mirror_status1</td>
</tr>
<tr>
<td>DNDM</td>
<td>Disable Disk Mirroring</td>
<td>extra_1: dbspace_number</td>
</tr>
<tr>
<td>DRAG</td>
<td>Drop Aggregate</td>
<td>dbname: database_nameobjname: aggregate_name login: owner</td>
</tr>
<tr>
<td>DRAM</td>
<td>Delete Audit Mask</td>
<td>login: user_id</td>
</tr>
<tr>
<td>DRBS</td>
<td>Drop Storage Space</td>
<td>dbname: storage_space_name</td>
</tr>
<tr>
<td>DRCK</td>
<td>Drop Chunk</td>
<td>dbname: dbspace_nameflags: mirror_status1 extra_2: path</td>
</tr>
<tr>
<td>DRCT</td>
<td>Drop Cast</td>
<td>dbname: database_nametabid: from_type_ID extra_1: from_type_xid partno: to_type_ID row_num: to_type_xid</td>
</tr>
<tr>
<td>DRDB</td>
<td>Drop Database</td>
<td>dbname: database_name</td>
</tr>
<tr>
<td>DRDS</td>
<td>Drop Dbspace</td>
<td>dbname: dbspace_name</td>
</tr>
<tr>
<td>DRIX</td>
<td>Drop Index</td>
<td>dbname: database_nametabid: table_id login: owner extra_2: index_name</td>
</tr>
<tr>
<td>DRLB</td>
<td>Drop Security Label</td>
<td>dbname: database_nameobjname: policy.label_name</td>
</tr>
<tr>
<td>DRLC</td>
<td>Drop Security Label Component</td>
<td>dbname: database_nameobjname: component_name</td>
</tr>
<tr>
<td>DRLG</td>
<td>Drop Transaction Log</td>
<td>extra_1: log_number</td>
</tr>
<tr>
<td>DRME</td>
<td>Drop Access Method</td>
<td>dbname: database_nametabid: access_method_ID objname: access_method_name login: access_method_owner</td>
</tr>
<tr>
<td>DROC</td>
<td>Drop Operator Class</td>
<td>dbname: database_nameobjname: operator_class_name login: owner</td>
</tr>
<tr>
<td>DRPL</td>
<td>Drop Security Policy</td>
<td>dbname: database_nameobjname: policy_name</td>
</tr>
<tr>
<td>DRRL</td>
<td>Drop Role</td>
<td>dbname: database_nameobjname: role_name</td>
</tr>
<tr>
<td>DRRT</td>
<td>Drop Named Row Type</td>
<td>dbname: database_nametabid: dropped_type_xid</td>
</tr>
<tr>
<td>DRSN</td>
<td>Drop Synonym</td>
<td>dbname: database_nametabid: synonym_table_id login: owner extra_2: synonym_name</td>
</tr>
<tr>
<td>DRSP</td>
<td>Drop SPL Routine</td>
<td>dbname: database_namelogin: owner extra_2: spname</td>
</tr>
<tr>
<td>DRSQ</td>
<td>Drop Sequence</td>
<td>dbname: database_nametabid: table_id</td>
</tr>
<tr>
<td>DRTB</td>
<td>Drop Table</td>
<td>dbname: database_nametabid: table_id objname: table_name login: owner flags: drop_flags21 extra_2: part_number_list</td>
</tr>
<tr>
<td>DRTR</td>
<td>Drop Trigger</td>
<td>dbname: database_namerow_num: trigger_id login: owner extra_2: trigger_name</td>
</tr>
<tr>
<td>DRUR</td>
<td>Drop User</td>
<td>objname: user_name</td>
</tr>
<tr>
<td>DRTX</td>
<td>Drop trusted context</td>
<td>objname: context_name</td>
</tr>
<tr>
<td>DRTY</td>
<td>Drop Type</td>
<td>dbname: database_nameobjname: type_name login: type_owner</td>
</tr>
<tr>
<td>DRVW</td>
<td>Drop View</td>
<td>dbname: database_nametabid: view_table_id flags: drop_flags21</td>
</tr>
<tr>
<td>DRXD</td>
<td>Drop XADatasource</td>
<td>dbname: database_nameobjname: owner objname: XA_data_source_name</td>
</tr>
<tr>
<td>DRXT</td>
<td>Drop XADatasource Type</td>
<td>dbname: database_nameobjname: owner objname: XA_data_source_type_name</td>
</tr>
<tr>
<td>EXSP</td>
<td>Execute SPL Routine</td>
<td>dbname: database_nametabid: proc_id</td>
</tr>
<tr>
<td>GRDB</td>
<td>Grant Database Access</td>
<td>dbname: database_nameextra_1: privilege5 extra_2: grantees4</td>
</tr>
<tr>
<td>GRDR</td>
<td>Grant Default Role</td>
<td>dbname: database_nameobjname: role_name login:grantor extra_2: grantees4</td>
</tr>
<tr>
<td>GRFR</td>
<td>Grant Fragment Access</td>
<td>dbname: database_nametabid: table_id objname: fragment extra_1: privilege5, 14 login: grantor extra_2: grantees4, 14</td>
</tr>
<tr>
<td>GRLB</td>
<td>Grant Security Label</td>
<td>dbname: database_nameobjname: policy.label_name login: grantee4 extra_2: access_type</td>
</tr>
<tr>
<td>GRRL</td>
<td>Grant Role</td>
<td>dbname: database_nameobjname: role_name login: grantor extra_2: grantees4</td>
</tr>
<tr>
<td>GRSA</td>
<td>Grant DBSECADM</td>
<td>login: grantee</td>
</tr>
<tr>
<td>GRSS</td>
<td>Grant SETSESSIONAUTH</td>
<td>dbname: database_namelogin: grantee extra_2: surrogate_user_list</td>
</tr>
<tr>
<td>GRTB</td>
<td>Grant Table Access</td>
<td>dbname: database_nametabid: table_id extra_1: privilege5, 14 login: grantor extra_2: grantee4, 14, update_columns, select_columns4, 14</td>
</tr>
<tr>
<td>GRXM</td>
<td>Grant Exemption</td>
<td>dbname: database_nameobjname: policy_name login: grantee extra_2: rule</td>
</tr>
<tr>
<td>INRW</td>
<td>Insert Row</td>
<td>dbname: database_nametabid: table_id partno: frag_id row_num: row_id</td>
</tr>
<tr>
<td>LGDB</td>
<td>Change Database Log Mode</td>
<td>dbname: database_nameflags: log_status6</td>
</tr>
<tr>
<td>LKTB</td>
<td>Lock Table</td>
<td>dbname: database_nametabid: table_id flags: lock_mode8</td>
</tr>
<tr>
<td>LSAM</td>
<td>List Audit Masks</td>
<td>none</td>
</tr>
<tr>
<td>LSDB</td>
<td>List Databases</td>
<td>none</td>
</tr>
<tr>
<td>MDLG</td>
<td>Modify Transaction Logging</td>
<td>flags: buffered_log_flags2</td>
</tr>
<tr>
<td>ONAU</td>
<td>onaudit</td>
<td>extra_2: command_line</td>
</tr>
<tr>
<td>ONBR</td>
<td>onbar</td>
<td>extra_2: command_line</td>
</tr>
<tr>
<td>ONCH</td>
<td>oncheck</td>
<td>extra_2: command_line</td>
</tr>
<tr>
<td>ONIN</td>
<td>oninit</td>
<td>extra_2: command_line</td>
</tr>
<tr>
<td>ONLG</td>
<td>onlog</td>
<td>extra_2: command_line</td>
</tr>
<tr>
<td>ONLO</td>
<td>onload</td>
<td>extra_2: command_line</td>
</tr>
<tr>
<td>ONMN</td>
<td>onmonitor</td>
<td>extra_2: command_line</td>
</tr>
<tr>
<td>ONMO</td>
<td>onmode</td>
<td>extra_2: command_line</td>
</tr>
<tr>
<td>ONPA</td>
<td>onparams</td>
<td>extra_2: command_line</td>
</tr>
<tr>
<td>ONPL</td>
<td>onpload</td>
<td>extra_2: command_line</td>
</tr>
<tr>
<td>ONSP</td>
<td>onspaces</td>
<td>extra_2: command_line</td>
</tr>
<tr>
<td>ONST</td>
<td>onstat</td>
<td>extra_2: command_line</td>
</tr>
<tr>
<td>ONTP</td>
<td>ontape</td>
<td>extra_2: command_line</td>
</tr>
<tr>
<td>ONUL</td>
<td>onunload</td>
<td>extra_2: command_line</td>
</tr>
<tr>
<td>OPDB</td>
<td>Open Database</td>
<td>dbname: database_nameflags: exclusive_flag extra_2: database_password</td>
</tr>
<tr>
<td>OPST</td>
<td>Optimize Storage</td>
<td>fragment <parameters>: part_numbers table <parameters>: table_name:database_name:owner_name compression purge_dictionary: date</td>
</tr>
<tr>
<td>PWUR</td>
<td>Set User Password</td>
<td>objname: user_name</td>
</tr>
<tr>
<td>RBSV</td>
<td>Rollback to Savepoint</td>
<td>dbname: database_name extra_1: transaction_id objname: savepoint_name</td>
</tr>
<tr>
<td>RDRW</td>
<td>Read Row</td>
<td>dbname: database_nametabid: table_id extra_1: part_number partno: frag_id row_num: row_id14</td>
</tr>
<tr>
<td>RLSV</td>
<td>Release Savepoint</td>
<td>dbname: database_name extra_1: transaction_id objname: savepoint_name</td>
</tr>
<tr>
<td>RLTX</td>
<td>Rollback Transaction</td>
<td>none</td>
</tr>
<tr>
<td>RMCK</td>
<td>Clear Mirrored Chunks</td>
<td>extra_1: dbspace_number</td>
</tr>
<tr>
<td>RNUR</td>
<td>Rename User</td>
<td>objname: old_user_nameextra_2: new_user_name</td>
</tr>
<tr>
<td>RNDB</td>
<td>Rename Database</td>
<td>dbname: database_nameobjname: new_dbname login: user_id</td>
</tr>
<tr>
<td>RNDS</td>
<td>Rename dbspace</td>
<td>dbname: dbspace_nameobjname: new_dbspace_name</td>
</tr>
<tr>
<td>RNIX</td>
<td>Rename Index</td>
<td>dbname: index_nameobjname: new_index_name</td>
</tr>
<tr>
<td>RNLB</td>
<td>Rename Security Label</td>
<td>dbname: database_nameobjname: old_policy.label_name extra_2: new_policy.label_name</td>
</tr>
<tr>
<td>RNLC</td>
<td>Rename Security Label Component</td>
<td>dbname: database_nameobjname: old_component_name extra_2: new_component_name</td>
</tr>
<tr>
<td>RNPL</td>
<td>Rename Security Policy</td>
<td>dbname: database_nameobjname: old_policy_name extra_2: new_policy_name</td>
</tr>
<tr>
<td>RNSQ</td>
<td>Rename Sequence</td>
<td>dbname: database_nametabid: table_id</td>
</tr>
<tr>
<td>RNTC</td>
<td>Rename Table&#x2F;Column</td>
<td>dbname: database_nametabid: table_id objname: new_table&#x2F;column_name extra_1: colno(*) login: owner extra_2: table_name(**)</td>
</tr>
<tr>
<td>RNTX</td>
<td>Rename trusted context</td>
<td>objname: context_nameextra_2: new_context name</td>
</tr>
<tr>
<td>RVDB</td>
<td>Revoke Database Access</td>
<td>dbname: database_name extra_1: privilege5 extra_2: revokees4</td>
</tr>
<tr>
<td>RVDR</td>
<td>Revoke Default Role</td>
<td>dbname: database_nameobjname: role_name login: revoker extra_2: revokees4</td>
</tr>
<tr>
<td>RVFR</td>
<td>Revoke Fragment Access</td>
<td>dbname: database_nametabid: table_id objname: fragment extra_1: privilege5, 14 login: revoker extra_2: revokees4, 14</td>
</tr>
<tr>
<td>RVLB</td>
<td>Revoke Security Label</td>
<td>dbname: database_nameobjname: policy.label_name login: grantee extra_2: access_type</td>
</tr>
<tr>
<td>RVRL</td>
<td>Revoke Role</td>
<td>dbname: database_nameobjname: role_name login: revoker extra_2: revokees4</td>
</tr>
<tr>
<td>RVSA</td>
<td>Revoke DBSECADM</td>
<td>login: grantee</td>
</tr>
<tr>
<td>RVSS</td>
<td>Revoke SETSESSIONAUTH</td>
<td>dbname: database_namelogin: grantee extra_2: surrogate_user_list</td>
</tr>
<tr>
<td>RVTB</td>
<td>Revoke Table Access</td>
<td>dbname: database_nametabid: table_id extra_1: privilege5, 14 login: revoker flags: drop_flags21 extra_2: revokees4, 14</td>
</tr>
<tr>
<td>RVXM</td>
<td>Revoke Exemption</td>
<td>dbname: database_nameobjname: policy_name login: grantee extra_2: rule</td>
</tr>
<tr>
<td>SCSP</td>
<td>System Command, SPL Routine</td>
<td>extra_2: command_string</td>
</tr>
<tr>
<td>STCO</td>
<td>Set Collation</td>
<td>dbname: database_nameobjname: locale_name</td>
</tr>
<tr>
<td>STCN</td>
<td>Set Constraint</td>
<td>dbname: database_nameflags: constraint_mode11 extra_2: constraint_names</td>
</tr>
<tr>
<td>STDF</td>
<td>Set Debug File</td>
<td>dbname: database_nameextra_2: file_path</td>
</tr>
<tr>
<td>STDP</td>
<td>Set Database Password</td>
<td>dbname: database_namelogin: user_id</td>
</tr>
<tr>
<td>STDS</td>
<td>Set Dataskip</td>
<td>flags: skip flags16extra_2: dbspace_list</td>
</tr>
<tr>
<td>STEP</td>
<td>Set Encryption Password</td>
<td>dbname: database_name</td>
</tr>
<tr>
<td>STEV</td>
<td>Set Environment</td>
<td>objname: environment_variable_and_value</td>
</tr>
<tr>
<td>STEX</td>
<td>Set Explain</td>
<td>flags: explain_flags12</td>
</tr>
<tr>
<td>STIL</td>
<td>Set Isolation Level</td>
<td>extra_1: isolation_level3</td>
</tr>
<tr>
<td>STLM</td>
<td>Set Lock Mode</td>
<td>flags: wait_flags13</td>
</tr>
<tr>
<td>STNC</td>
<td>Set No Collation</td>
<td>dbname: database_nameobjname: locale_name</td>
</tr>
<tr>
<td>STOM</td>
<td>Set Object Mode</td>
<td>dbname: database_nametabid: table_id extra_1: command_mode_flag22 flags: object_type_flag23 extra_2: object_names</td>
</tr>
<tr>
<td>STOP</td>
<td>Stop Violations</td>
<td>dbname: database_nametabid: table_id</td>
</tr>
<tr>
<td>STPR</td>
<td>Set Pdqpriority</td>
<td>flags: priority_level17</td>
</tr>
<tr>
<td>STRL</td>
<td>Set Role</td>
<td>dbname: database_nameobjname: role_name</td>
</tr>
<tr>
<td>STRS</td>
<td>Set Resident</td>
<td>dbname: database_nameobjname: fragment_list extra_1: fragment_information</td>
</tr>
<tr>
<td>STRT</td>
<td>Start Violations</td>
<td>dbname: database_nametabid: table_id extra_1: Vio_tid flags: Dia_tid</td>
</tr>
<tr>
<td>STSA</td>
<td>Set Session Authorization</td>
<td>dbname: database_namelogin: new_user_name</td>
</tr>
<tr>
<td>STSC</td>
<td>Set Statement Cache</td>
<td>objname: statement_name</td>
</tr>
<tr>
<td>STSN</td>
<td>Start New Session</td>
<td>none</td>
</tr>
<tr>
<td>STSV</td>
<td>Set Savepoint</td>
<td>dbname: database_name extra_1: transaction_id objname: savepoint_name</td>
</tr>
<tr>
<td>STTX</td>
<td>Set Transaction Mode</td>
<td>extra_1: operation20flags: mode_flags19 extra_2:</td>
</tr>
<tr>
<td>SVXD</td>
<td>Save External Directives</td>
<td>dbname: database_nameobjname: active&#x2F;inactive&#x2F;test objname: directive_text</td>
</tr>
<tr>
<td>TCTB</td>
<td>Truncate Table</td>
<td>dbname: database_nametabid: table_id objname: table_name</td>
</tr>
<tr>
<td>ULTB</td>
<td>Unlock Table</td>
<td>dbname: database_nametabid: table_id</td>
</tr>
<tr>
<td>UPAM</td>
<td>Update Audit Mask</td>
<td>login: user id</td>
</tr>
<tr>
<td>UPCK</td>
<td>Bring Chunk Online</td>
<td>extra_1: chunk_numberflags: mirror_status1</td>
</tr>
<tr>
<td>UPDM</td>
<td>Enable Disk Mirroring</td>
<td>extra_1: dbspace_number</td>
</tr>
<tr>
<td>UPRW</td>
<td>Update Current® Row</td>
<td>dbname: database_nametabid: table_id extra_1: old_part_number row_num: old_row_id14 flags: new_row_id extra_2: new_part_number</td>
</tr>
<tr>
<td>USSP</td>
<td>Update Statistics, SPL Routine</td>
<td>dbname: database_nametabid: proc_id</td>
</tr>
<tr>
<td>USTB</td>
<td>Update Statistics, Table</td>
<td>dbname: database_nametabid: table_id</td>
</tr>
</tbody></table>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%AE%A1%E8%AE%A1/" rel="tag">审计</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
    <article
  id="post-GBase8s的Server和CM的日志按天分片"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/05/10/GBase8s%E7%9A%84Server%E5%92%8CCM%E7%9A%84%E6%97%A5%E5%BF%97%E6%8C%89%E5%A4%A9%E5%88%86%E7%89%87/"
    >GBase8s的Server和CM的日志按天分片</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/05/10/GBase8s%E7%9A%84Server%E5%92%8CCM%E7%9A%84%E6%97%A5%E5%BF%97%E6%8C%89%E5%A4%A9%E5%88%86%E7%89%87/" class="article-date">
  <time datetime="2023-05-10T01:12:47.000Z" itemprop="datePublished">2023-05-10</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/GBase8s/">GBase8s</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h1 id="将GBase8是的Server和CM的日志按天分片"><a href="#将GBase8是的Server和CM的日志按天分片" class="headerlink" title="将GBase8是的Server和CM的日志按天分片"></a>将GBase8是的Server和CM的日志按天分片</h1><h2 id="分片脚本-x2F-home-x2F-gbase-x2F-shell-x2F-logsplit-sh"><a href="#分片脚本-x2F-home-x2F-gbase-x2F-shell-x2F-logsplit-sh" class="headerlink" title="分片脚本:  &#x2F;home&#x2F;gbase&#x2F;shell&#x2F;logsplit.sh"></a>分片脚本:  &#x2F;home&#x2F;gbase&#x2F;shell&#x2F;logsplit.sh</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">!/bin/bash</span></span><br><span class="line"></span><br><span class="line">timelog=$(date &#x27;+%Y%m%d_%H%M%S&#x27;)</span><br><span class="line">dblog=online.log</span><br><span class="line">cmlog=$(cat /opt/gbase/etc/cmsm.cfg |awk &#x27;$1==&quot;LOGFILE&quot;&#123;print $2&#125;&#x27;|awk -F &#x27;/&#x27; &#x27;&#123;print $NF&#125;&#x27;)</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="built_in">echo</span> <span class="variable">$dblog</span></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="built_in">echo</span> <span class="variable">$cmlog</span></span></span><br><span class="line"></span><br><span class="line">cd /opt/gbase/tmp</span><br><span class="line">cp $dblog $&#123;dblog&#125;_$&#123;timelog&#125;</span><br><span class="line"><span class="meta prompt_">&gt; </span><span class="language-bash"><span class="variable">$dblog</span></span></span><br><span class="line"></span><br><span class="line">cp $cmlog $&#123;cmlog&#125;_$&#123;timelog&#125;</span><br><span class="line"><span class="meta prompt_">&gt; </span><span class="language-bash"><span class="variable">$cmlog</span></span></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="定时任务"><a href="#定时任务" class="headerlink" title="定时任务"></a>定时任务</h2><p>​		每天23点55分执行执行一次上面的脚本。crontab的内容添加如下一个条目：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">55 23 * * * /home/gbase/shell/logsplit.sh </span><br></pre></td></tr></table></figure>







 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%97%A5%E5%BF%97%E5%88%86%E5%89%B2/" rel="tag">日志分割</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
    <article
  id="post-GBase8s备份策略备份程序部署查看"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/05/10/GBase8s%E5%A4%87%E4%BB%BD%E7%AD%96%E7%95%A5%E5%A4%87%E4%BB%BD%E7%A8%8B%E5%BA%8F%E9%83%A8%E7%BD%B2%E6%9F%A5%E7%9C%8B/"
    >GBase8s备份策略备份程序部署查看</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/05/10/GBase8s%E5%A4%87%E4%BB%BD%E7%AD%96%E7%95%A5%E5%A4%87%E4%BB%BD%E7%A8%8B%E5%BA%8F%E9%83%A8%E7%BD%B2%E6%9F%A5%E7%9C%8B/" class="article-date">
  <time datetime="2023-05-10T01:10:21.000Z" itemprop="datePublished">2023-05-10</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/GBase8s/">GBase8s</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h1 id="GBase8s备份策略-x2F-备份程序-x2F-部署-x2F-查看"><a href="#GBase8s备份策略-x2F-备份程序-x2F-部署-x2F-查看" class="headerlink" title="GBase8s备份策略&#x2F;备份程序&#x2F;部署&#x2F;查看"></a>GBase8s备份策略&#x2F;备份程序&#x2F;部署&#x2F;查看</h1><h2 id="备份策略"><a href="#备份策略" class="headerlink" title="备份策略"></a>备份策略</h2><ul>
<li>每天晚上10点开始备份</li>
<li>周6是全量备份</li>
<li>周1&#x2F;2&#x2F;3&#x2F;4&#x2F;5和周日是增量备份</li>
<li>备份文件保留两周</li>
<li>备份文件存储目录： &#x2F;Gbase8sBackupDir&#x2F;$GBASEDBTSERVER</li>
</ul>
<h2 id="备份程序"><a href="#备份程序" class="headerlink" title="备份程序"></a>备份程序</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">!/bin/bash</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">filename: /Gbase8sBackupDir/shell/Gbase8sBackup.sh</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="keyword">function</span>: GBase 8s Database Server backup shell.</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">write by: liaosnet@gbasedbt.com 2022-09-05</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">update by : wangwei5@gbasedbt.com 2022-11-29</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">if [ &quot;X$1&quot; == &quot;X&quot; ] ; then</span><br><span class="line">	echo &quot;Environment variables are not loaded correctly.&quot;</span><br><span class="line">	exit 11</span><br><span class="line">fi</span><br><span class="line">. $1</span><br><span class="line"></span><br><span class="line">export LANG=C</span><br><span class="line">WORKDIR=/Gbase8sBackupDir/$GBASEDBTSERVER</span><br><span class="line">LOGFILE=$&#123;WORKDIR:-$(pwd)&#125;/backup_status.log</span><br><span class="line">[ ! -f $&#123;LOGFILE&#125; ] &amp;&amp; touch $&#123;LOGFILE&#125;</span><br><span class="line">loginfo()&#123;</span><br><span class="line">  echo -e &quot;[$(date +&#x27;%Y-%m-%d %H:%M:%S&#x27;)] $*&quot; &gt;&gt; $&#123;LOGFILE&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">L0DAY=6</span><br><span class="line">L1DAY=0,1,2,3,4,5</span><br><span class="line">L2DAY=8</span><br><span class="line">KEEPDAYS=14</span><br><span class="line">USERNAME=gbasedbt</span><br><span class="line">DBSTATUS=$(onstat -c|grep &#x27;On-Line&#x27;|wc -l)</span><br><span class="line">BACKUPDIR=$WORKDIR</span><br><span class="line">CURRDAY=$(date +%w)</span><br><span class="line">HADBACKUP=$(onstat -g arc | awk &#x27;$1==&quot;name&quot;&#123;need=1&#125;need==1&amp;&amp;$3==&quot;0&quot;&#123;print &quot;1&quot;;exit&#125;&#x27;)</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># check env</span></span></span><br><span class="line">if [ ! x&quot;$(whoami)&quot; = &quot;x$&#123;USERNAME&#125;&quot; ]; then</span><br><span class="line">  loginfo &quot;Must run as user: $&#123;USERNAME&#125;&quot;</span><br><span class="line">  exit 100</span><br><span class="line">fi </span><br><span class="line"></span><br><span class="line">if [ ! &quot;x$&#123;DBSTATUS&#125;&quot; = &quot;x1&quot; ]; then</span><br><span class="line">  loginfo &quot;Backup ONLY run On-Line Server which is Primary Server or Standard Server.&quot;</span><br><span class="line">  exit 4</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line">if [ ! -d $&#123;BACKUPDIR&#125; ];then</span><br><span class="line">  loginfo &quot;The Backup dir is not exists.&quot;</span><br><span class="line">  exit 3</span><br><span class="line">fi</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># backup db</span></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">delete file</span></span><br><span class="line">loginfo &quot;Delete files at $BACKUPDIR which out $&#123;KEEPDAYS:-30&#125; days.&quot;</span><br><span class="line">cd $BACKUPDIR &amp;&amp; find $BACKUPDIR -name &quot;*L[0-2]&quot; -type f -ctime +$&#123;KEEPDAYS:-30&#125; | xargs rm -rf</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">backup db</span></span><br><span class="line">if [ x&quot;$HADBACKUP&quot; = x ]; then</span><br><span class="line">  loginfo &quot;Execute L0 backup start, while no backup found.&quot;</span><br><span class="line">  CURRDAY=9</span><br><span class="line">  ontape -s -L 0</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line">if [[ $&#123;L0DAY&#125; =~ $&#123;CURRDAY&#125; ]]; then</span><br><span class="line">  loginfo &quot;Execute L0 backup start...&quot;</span><br><span class="line">  ontape -s -L 0</span><br><span class="line">elif [[ $&#123;L1DAY&#125; =~ $&#123;CURRDAY&#125; ]]; then</span><br><span class="line">  loginfo &quot;Execute L1 backup start...&quot;</span><br><span class="line">  ontape -s -L 1</span><br><span class="line">elif [[ $&#123;L2DAY&#125; =~ $&#123;CURRDAY&#125; ]]; then</span><br><span class="line">  loginfo &quot;Execute L2 backup start...&quot;</span><br><span class="line">  ontape -s -L 2</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line">if [ $? -eq 0 ];then</span><br><span class="line">  loginfo &quot;Execute backup finished.&quot;</span><br><span class="line">  exit 0</span><br><span class="line">else</span><br><span class="line">  loginfo &quot;Execute backup error.&quot;</span><br><span class="line">  exit 1</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="部署备份程序"><a href="#部署备份程序" class="headerlink" title="部署备份程序"></a>部署备份程序</h2><h5 id="创建备份目录"><a href="#创建备份目录" class="headerlink" title="创建备份目录"></a>创建备份目录</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">root用户执行：</span></span><br><span class="line">mkdir /Gbase8sBackupDir</span><br><span class="line">chown gbasedbt:gbasedbt /Gbase8sBackupDir</span><br><span class="line">su - gbasedbt</span><br></pre></td></tr></table></figure>

<h5 id="上传备份程序"><a href="#上传备份程序" class="headerlink" title="上传备份程序"></a>上传备份程序</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">gbasedbt用户执行：</span></span><br><span class="line">onmode -wf TAPEDEV=/Gbase8sBackupDir/$GBASEDBTSERVER</span><br><span class="line">mkdir /Gbase8sBackupDir/$GBASEDBTSERVER</span><br><span class="line">mkdir /Gbase8sBackupDir/shell</span><br><span class="line">cat &gt; /Gbase8sBackupDir/shell/Gbase8sBackup.sh</span><br><span class="line">...把上面的备份程序整个复制粘贴到这里后，Ctrl+d 保存。</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">gbasedbt用户执行：</span></span><br><span class="line">chmod 750 /Gbase8sBackupDir/shell/Gbase8sBackup.sh</span><br></pre></td></tr></table></figure>

<h5 id="部署定时任务"><a href="#部署定时任务" class="headerlink" title="部署定时任务"></a>部署定时任务</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">gbasedbt用户执行：</span></span><br><span class="line">crontab -e</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">0 22 * * *  /Gbase8sBackupDir/shell/Gbase8sBackup.sh /home/gbasedbt/.bash_profile &gt; /Gbase8sBackupDir/shell/Gbase8sBackup.log 2&gt;&amp;1 </span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">:wq</span><br></pre></td></tr></table></figure>



<p>— 部署完成，等待时间，检测备份文件。</p>
<h2 id="检测备份情况"><a href="#检测备份情况" class="headerlink" title="检测备份情况"></a>检测备份情况</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">gbasedbt用户操作：</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># 检查ontape日志：</span></span></span><br><span class="line">cat /Gbase8sBackupDir/shell/Gbase8sBackup.log</span><br><span class="line">cat /Gbase8sBackupDir/$GBASEDBTSERVER/backup_status.log</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># 检查数据库日志：</span></span></span><br><span class="line">onstat -m</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># 检查arc命令：</span></span></span><br><span class="line">onstat -g arc</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># 检查备份文件：</span></span></span><br><span class="line">ls -lrt /Gbase8sBackupDir/$GBASEDBTSERVER</span><br></pre></td></tr></table></figure>

 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%A4%87%E4%BB%BD%E9%83%A8%E7%BD%B2/" rel="tag">备份部署</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
    <article
  id="post-入门-JAVA之路"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/05/10/%E5%85%A5%E9%97%A8-JAVA%E4%B9%8B%E8%B7%AF/"
    >入门-JAVA之路</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/05/10/%E5%85%A5%E9%97%A8-JAVA%E4%B9%8B%E8%B7%AF/" class="article-date">
  <time datetime="2023-05-10T01:00:57.000Z" itemprop="datePublished">2023-05-10</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/Java/">Java</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h1 id="JAVA个人环境准备"><a href="#JAVA个人环境准备" class="headerlink" title="JAVA个人环境准备"></a>JAVA个人环境准备</h1><h2 id="下载IDEA2021-2-3"><a href="#下载IDEA2021-2-3" class="headerlink" title="下载IDEA2021.2.3"></a>下载IDEA2021.2.3</h2><p><a target="_blank" rel="noopener" href="https://www.jetbrains.com/idea/download/other.html">https://www.jetbrains.com/idea/download/other.html</a>  靠下位置有，已经下载到“下载目录”</p>
<h2 id="下载JDK8"><a href="#下载JDK8" class="headerlink" title="下载JDK8"></a>下载JDK8</h2><p><a target="_blank" rel="noopener" href="https://www.oracle.com/java/technologies/downloads/#java8">https://www.oracle.com/java/technologies/downloads/#java8</a>  考下位置有，已经下载到“下载目录”</p>
<h2 id="安装JDK8"><a href="#安装JDK8" class="headerlink" title="安装JDK8"></a>安装JDK8</h2><ul>
<li><strong>卸载jdk18步骤：</strong></li>
</ul>
<ol>
<li>删除目录 D:\install\jdk-18； 我这里直接改名： D:\install\jdk-18太新了不用</li>
<li>删除JAVA_HOME</li>
<li>删除PATH  (JDK18的只有jdk&#x2F;bin目录，没有jre&#x2F;并目录)</li>
</ol>
<ul>
<li><strong>安装jdk8步骤：</strong></li>
</ul>
<ol>
<li>安装软件到 D:\install\jdk8</li>
<li>添加 JAVA_HOME  D:\install\jdk8</li>
<li>添加PATH  D:\install\jdk8\bin  D:\install\jdk8\jre\bin</li>
<li>删除PATH C:\Program Files (x86)\Common Files\Oracle\Java\javapath</li>
</ol>
<h2 id="安装破解IDEA2021-2-3"><a href="#安装破解IDEA2021-2-3" class="headerlink" title="安装破解IDEA2021.2.3"></a>安装破解IDEA2021.2.3</h2><ol>
<li>参考破解网址： <a target="_blank" rel="noopener" href="http://www.itmind.net/10705.html">http://www.itmind.net/10705.html</a></li>
<li>卸载IDEA2022</li>
<li>安装IDEA2021.2.3.exe</li>
<li>安装目录： D:\install\IDEA2021.2.3  (勾选桌面图标 和 .java)</li>
<li>启动IDEA</li>
<li>Start trial ： 注册JETBRAINS账号使用github账号wangwei129, WANG WEI 密码 a&amp;89Uiojkl</li>
<li>新建java项目 ：参考 <a target="_blank" rel="noopener" href="http://www.itmind.net/5859.html">http://www.itmind.net/5859.html</a></li>
<li>然后依次点击菜单 <code>Help -&gt; Edit Custom VM Options</code> 来通过 IDEA 修改 <code>idea.vmoptions</code> 文件, 在末尾添加解补丁:</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">-javaagent:D:\\IDEA30TRIAL\FineAgent.jar</span><br></pre></td></tr></table></figure>

<p>​	9. 补丁FineAgent.jar可获取 :</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">补丁安装教程：http://www.itmind.net/10701.html</span><br><span class="line">补丁网盘链接: https://pan.baidu.com/s/1E7URZ_bTe3XTvyUOEBsYIw 提取码: cv5c</span><br><span class="line">备用链接: https://pan.baidu.com/s/1gERUKH934jiZekIligoP-Q 提取码: 3v6a</span><br><span class="line">长按扫描下方二维码加我微信，私信我 888 拉你入群，第一时间获取更新信息~~</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">补丁已经保存到我的网盘2022目录下</span></span><br></pre></td></tr></table></figure>

<pre><code>10. 关闭IDEA
</code></pre>
<ol start="11">
<li><p>启动IDEA</p>
</li>
<li><p>现在注册码注册</p>
</li>
<li><p>把中D:\IDEA30TRIAL\ActivationCode.txt的注册码复制填进去</p>
</li>
<li><p>破解完成。</p>
<p>注明：自动导入包和删包： 文件-设置-编辑-常规-自动导入</p>
</li>
</ol>
<h2 id="下载安装Tomcat8"><a href="#下载安装Tomcat8" class="headerlink" title="下载安装Tomcat8"></a>下载安装Tomcat8</h2><p><a target="_blank" rel="noopener" href="https://tomcat.apache.org/download-80.cgi">https://tomcat.apache.org/download-80.cgi</a></p>
<p>解压即安装：安装目录  D:\install\apache-tomcat-8.5.78-windows-x64\apache-tomcat-8.5.78</p>
<p>启动 start.bat</p>
<p>停止 stop.bat</p>
<p>把你的war包放在 D:\install\apache-tomcat-8.5.78-windows-x64\apache-tomcat-8.5.78\webapps 目录下即可</p>
<blockquote>
<p>1、tomcat窗口中内容中文<a target="_blank" rel="noopener" href="https://so.csdn.net/so/search?q=%E4%B9%B1%E7%A0%81&spm=1001.2101.3001.7020">乱码</a>解决：<br>找到tomcat下conf文件夹下的logging.<a target="_blank" rel="noopener" href="https://so.csdn.net/so/search?q=properties&spm=1001.2101.3001.7020">properties</a>文件，打开后找到<br>java.util.logging.ConsoleHandler.encoding &#x3D; UTF-8，将其修改为<br>java.util.logging.ConsoleHandler.encoding &#x3D; GBK </p>
</blockquote>
<p>注明： 直接把这个安装目录上传到linux上，页可以使用，使用sh启停。</p>
<hr>
<h1 id="JAVA-web项目实战流程"><a href="#JAVA-web项目实战流程" class="headerlink" title="JAVA web项目实战流程"></a>JAVA web项目实战流程</h1><h2 id="新建web项目"><a href="#新建web项目" class="headerlink" title="新建web项目"></a>新建web项目</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">1. File - New - Project</span><br><span class="line">2. Java - Next</span><br><span class="line">3. 不选择任何模板</span><br><span class="line">4. 给项目取名字webdemo</span><br><span class="line">5. 选中创建好的项目 - 右键 - Add Framework Support - Java Web</span><br><span class="line">6. Run - Edit Configurations - Edit configuration templates... - Tomcat Server - Local  - Application Server: - Configure... - 选择Tomcat的安装目录</span><br><span class="line">7. Run - Edit Configurations - + - Tomcat Server -  选择打包内容 修改打包名(即是war包名或路径名)</span><br><span class="line">8. 运行Web项目</span><br></pre></td></tr></table></figure>



<h2 id="第一个Servlet页面"><a href="#第一个Servlet页面" class="headerlink" title="第一个Servlet页面"></a>第一个Servlet页面</h2><h3 id="1-添加tomcat的jar包"><a href="#1-添加tomcat的jar包" class="headerlink" title="1. 添加tomcat的jar包"></a>1. 添加tomcat的jar包</h3><blockquote>
<ol>
<li><p>右键工程</p>
</li>
<li><p>Open module setging 模块设置</p>
</li>
<li><p>Libraries</p>
</li>
<li><p>+java</p>
</li>
<li><p>打开目录D:\install\apache-tomcat-8.5.78-windows-x64\apache-tomcat-8.5.78\lib</p>
</li>
<li><p>添加jsp-api.jar和servlet-api.jar两个包</p>
</li>
<li><p>起名Name：lib</p>
</li>
<li><p>Apply - OK</p>
</li>
</ol>
</blockquote>
<h3 id="2-src"><a href="#2-src" class="headerlink" title="2. src"></a>2. src</h3><blockquote>
<p>新建包： com.trey.servlet</p>
<p>新建类： Servlet001.java</p>
<p>继承：     extends HttpServlet</p>
<p>重写方法：  doGet  &#x2F;  doPost</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Servlet001</span> <span class="keyword">extends</span> <span class="title class_">HttpServlet</span> &#123;</span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">doGet</span><span class="params">(HttpServletRequest req, HttpServletResponse resp)</span> <span class="keyword">throws</span> ServletException, IOException &#123;</span><br><span class="line">     resp.setContentType(<span class="string">&quot;text/html&quot;</span>);</span><br><span class="line">     <span class="type">PrintWriter</span> <span class="variable">writer</span> <span class="operator">=</span> resp.getWriter();</span><br><span class="line">     writer.println(<span class="string">&quot;&lt;html&gt;&lt;body&gt;&quot;</span>);</span><br><span class="line">     <span class="type">String</span> <span class="variable">s</span> <span class="operator">=</span> <span class="string">&quot;Hello servlet Web&quot;</span>;</span><br><span class="line">     writer.println(s);</span><br><span class="line">     writer.println(<span class="string">&quot;&lt;/body&gt;&lt;/html&gt;&quot;</span>);</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">doPost</span><span class="params">(HttpServletRequest req, HttpServletResponse resp)</span> <span class="keyword">throws</span> ServletException, IOException &#123;</span><br><span class="line">     <span class="built_in">super</span>.doPost(req, resp);</span><br><span class="line"> &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</blockquote>
<h3 id="3-web-xml"><a href="#3-web-xml" class="headerlink" title="3. web.xml"></a>3. web.xml</h3><blockquote>
<ol>
<li><servlet>
</li>
<li><servlet-mapping></li>
</ol>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=<span class="string">&quot;1.0&quot;</span> encoding=<span class="string">&quot;UTF-8&quot;</span>?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">web-app</span> <span class="attr">xmlns</span>=<span class="string">&quot;http://xmlns.jcp.org/xml/ns/javaee&quot;</span></span></span><br><span class="line"><span class="tag">         <span class="attr">xmlns:xsi</span>=<span class="string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span></span><br><span class="line"><span class="tag">         <span class="attr">xsi:schemaLocation</span>=<span class="string">&quot;http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd&quot;</span></span></span><br><span class="line"><span class="tag">         <span class="attr">version</span>=<span class="string">&quot;4.0&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">servlet</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">servlet-name</span>&gt;</span>servlet001<span class="tag">&lt;/<span class="name">servlet-name</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">servlet-class</span>&gt;</span>com.trey.servlet.Servlet001<span class="tag">&lt;/<span class="name">servlet-class</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">servlet</span>&gt;</span></span><br><span class="line">    </span><br><span class="line">    <span class="tag">&lt;<span class="name">servlet-mapping</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">servlet-name</span>&gt;</span>servlet001<span class="tag">&lt;/<span class="name">servlet-name</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">url-pattern</span>&gt;</span>/hello<span class="tag">&lt;/<span class="name">url-pattern</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">servlet-mapping</span>&gt;</span></span><br><span class="line">    </span><br><span class="line"><span class="tag">&lt;/<span class="name">web-app</span>&gt;</span></span><br></pre></td></tr></table></figure>
</blockquote>
<h3 id="4-启动项目"><a href="#4-启动项目" class="headerlink" title="4. 启动项目"></a>4. 启动项目</h3><h3 id="5-访问网站"><a href="#5-访问网站" class="headerlink" title="5. 访问网站"></a>5. 访问网站</h3><blockquote>
<p><a target="_blank" rel="noopener" href="http://localhost:8080/webdemo_war/">http://localhost:8080/webdemo_war/</a>            项目主页</p>
<p><a target="_blank" rel="noopener" href="http://localhost:8080/webdemo_war/hello">http://localhost:8080/webdemo_war/hello</a>   第一个servlet页</p>
</blockquote>
<h1 id="打包IDEA项目成war包"><a href="#打包IDEA项目成war包" class="headerlink" title="打包IDEA项目成war包"></a>打包IDEA项目成war包</h1><h2 id="打包和发布"><a href="#打包和发布" class="headerlink" title="打包和发布"></a>打包和发布</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">1、进入Project Structre </span><br><span class="line">	（文件 - 项目结构）</span><br><span class="line">2、找到Atrtifacts模块 —&gt; 点击左上角添加 —&gt; Web Application: Archive —&gt; For &quot; &quot;</span><br><span class="line">	（工件 - 添加 - web应用程序：归档 - for&quot;Web名称&quot;）</span><br><span class="line">3、指定名称和输出路径；点击下方 + 号，选择 Directory Content</span><br><span class="line">	（打包取名： webdemo）</span><br><span class="line">	（输出路径： D:\go\src\webdemo\out\artifacts\webdemo）</span><br><span class="line">	（Directory Content好像不用做）</span><br><span class="line">4、选择项目的 WebRoot目录 ，点击 ok</span><br><span class="line">	（Directory Content好像不用做）</span><br><span class="line">5、回到主页面，点击 Build -&gt; 选择 Build Artifacts -&gt; 选择刚刚生成的artifact -&gt; 点击 build</span><br><span class="line">6、等待build结束，在指定的输出路径中拿到war包</span><br><span class="line">	（D:\go\src\webdemo\out\artifacts\webdemo\webdemo.war）</span><br><span class="line">7、把war包上传到tomcat的webapps目录即可</span><br></pre></td></tr></table></figure>



<hr>
<h1 id="Servlet-JSP-JDBC综合案例"><a href="#Servlet-JSP-JDBC综合案例" class="headerlink" title="Servlet+JSP+JDBC综合案例"></a>Servlet+JSP+JDBC综合案例</h1><h2 id="新建WEB项目"><a href="#新建WEB项目" class="headerlink" title="新建WEB项目"></a>新建WEB项目</h2><p>​	如上</p>
<h2 id="添加数据库驱动包"><a href="#添加数据库驱动包" class="headerlink" title="添加数据库驱动包"></a>添加数据库驱动包</h2><blockquote>
<ol>
<li>WEB-INF  下新建目录 lib</li>
<li>把D:\jdbc\mysql\mysql-connector-java-5.1.42-bin.jar 复制到 lib</li>
<li>后续动作如上（添加tomcat的jar包）。</li>
</ol>
</blockquote>
<h2 id="测试一下jdbc"><a href="#测试一下jdbc" class="headerlink" title="测试一下jdbc"></a>测试一下jdbc</h2><blockquote>
<ol>
<li>新建包 com.trey.testjdbc</li>
<li>新建类 TestJdbc</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.trey.testjdbc;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.sql.Connection;</span><br><span class="line"><span class="keyword">import</span> java.sql.DriverManager;</span><br><span class="line"><span class="keyword">import</span> java.sql.SQLException;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestJdbc</span> &#123;</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">     <span class="keyword">try</span> &#123;</span><br><span class="line">         Class.forName(<span class="string">&quot;com.mysql.jdbc.Driver&quot;</span>);</span><br><span class="line">         <span class="type">String</span> <span class="variable">url</span> <span class="operator">=</span> <span class="string">&quot;jdbc:mysql://1.1.1.3:3306/bookdb?useUnicode=true&amp;characterEncoding=UTF-8&quot;</span>;</span><br><span class="line">         <span class="type">String</span> <span class="variable">user</span> <span class="operator">=</span> <span class="string">&quot;root&quot;</span>;</span><br><span class="line">         <span class="type">String</span> <span class="variable">password</span> <span class="operator">=</span> <span class="string">&quot;Passwd123&quot;</span>;</span><br><span class="line">         <span class="type">Connection</span> <span class="variable">connection</span> <span class="operator">=</span> DriverManager.getConnection(url,user,password);</span><br><span class="line">         System.out.println(connection);</span><br><span class="line">     &#125; <span class="keyword">catch</span> (ClassNotFoundException e) &#123;</span><br><span class="line">         e.printStackTrace();</span><br><span class="line">     &#125; <span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">         e.printStackTrace();</span><br><span class="line">     &#125;</span><br><span class="line"> &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>运行测试类，能够正常拿到connection没有任何报错，证明jdbc正常。</li>
</ol>
</blockquote>
<h2 id="在mysql中创建表user"><a href="#在mysql中创建表user" class="headerlink" title="在mysql中创建表user"></a>在mysql中创建表user</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* </span></span><br><span class="line"><span class="comment">select * from mysql.user;</span></span><br><span class="line"><span class="comment">flush privileges;</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> IF <span class="keyword">EXISTS</span> `<span class="keyword">user</span>`;</span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> `<span class="keyword">user</span>`  (</span><br><span class="line">  `id` <span class="type">int</span>(<span class="number">11</span>) <span class="keyword">NOT</span> <span class="keyword">NULL</span> AUTO_INCREMENT,</span><br><span class="line">  `name` <span class="type">varchar</span>(<span class="number">9</span>) <span class="type">CHARACTER</span> <span class="keyword">SET</span> utf8 <span class="keyword">COLLATE</span> utf8_general_ci <span class="keyword">NOT</span> <span class="keyword">NULL</span>,</span><br><span class="line">  `age` <span class="type">int</span>,</span><br><span class="line">  `register` datetime,</span><br><span class="line">  <span class="keyword">PRIMARY</span> KEY (`id`) <span class="keyword">USING</span> BTREE </span><br><span class="line">) ENGINE <span class="operator">=</span> InnoDB AUTO_INCREMENT <span class="operator">=</span> <span class="number">5</span> <span class="type">CHARACTER</span> <span class="keyword">SET</span> <span class="operator">=</span> utf8 <span class="keyword">COLLATE</span> <span class="operator">=</span> utf8_general_ci ROW_FORMAT <span class="operator">=</span> Compact</span><br><span class="line">;</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> <span class="keyword">user</span>(name,age,register) <span class="keyword">values</span>(<span class="string">&#x27;张三&#x27;</span>,<span class="number">36</span>,<span class="string">&#x27;2022-05-22 08:00:00&#x27;</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> <span class="keyword">user</span>(name,age,register) <span class="keyword">values</span>(<span class="string">&#x27;李四&#x27;</span>,<span class="number">36</span>,<span class="string">&#x27;2022-05-22 08:00:00&#x27;</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> <span class="keyword">user</span>(name,age,register) <span class="keyword">values</span>(<span class="string">&#x27;王五&#x27;</span>,<span class="number">36</span>,<span class="string">&#x27;2022-05-22 08:00:00&#x27;</span>);</span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> <span class="keyword">user</span>;</span><br></pre></td></tr></table></figure>

<h2 id="包类规划"><a href="#包类规划" class="headerlink" title="包类规划"></a>包类规划</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.trey.entity;      <span class="comment">//实体包   Student 				 //实体类</span></span><br><span class="line"><span class="keyword">package</span> com.trey.repository;  <span class="comment">//储藏包   StudentRepository      //储藏类</span></span><br><span class="line"><span class="keyword">package</span> com.trey.servlet;     <span class="comment">//控制包	  StudentServlet         //控制类</span></span><br><span class="line"><span class="keyword">package</span> com.trey.filter;      <span class="comment">//过滤器包  CharacterFilter       //过滤器类</span></span><br><span class="line"><span class="keyword">package</span> com.trey.entity;  <span class="comment">//实体类</span></span><br><span class="line"><span class="keyword">package</span> com.trey.entity;  <span class="comment">//实体类</span></span><br></pre></td></tr></table></figure>

<h2 id="java-查询-mysql"><a href="#java-查询-mysql" class="headerlink" title="java 查询 mysql"></a>java 查询 mysql</h2><p>注明：自动生成getter和setter的快捷键是alt+insert，然后选中所有字段即可。</p>
<h4 id="实体类"><a href="#实体类" class="headerlink" title="实体类"></a>实体类</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.trey.entity;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.Date;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Student</span> &#123;</span><br><span class="line">    <span class="keyword">private</span> Integer id;</span><br><span class="line">    <span class="keyword">private</span> String  name;</span><br><span class="line">    <span class="keyword">private</span> Double age;</span><br><span class="line">    <span class="keyword">private</span> Date register;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> Integer <span class="title function_">getId</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> id;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setId</span><span class="params">(Integer id)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.id = id;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">getName</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> name;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setName</span><span class="params">(String name)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.name = name;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> Double <span class="title function_">getAge</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> age;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setAge</span><span class="params">(Double age)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.age = age;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> Date <span class="title function_">getRegister</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> register;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setRegister</span><span class="params">(Date register)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.register = register;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="title function_">Student</span><span class="params">(Integer id, String name, Double age, Date register)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.id = id;</span><br><span class="line">        <span class="built_in">this</span>.name = name;</span><br><span class="line">        <span class="built_in">this</span>.age = age;</span><br><span class="line">        <span class="built_in">this</span>.register = register;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">toString</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;Student&#123;&quot;</span> +</span><br><span class="line">                <span class="string">&quot;id=&quot;</span> + id +</span><br><span class="line">                <span class="string">&quot;, name=&#x27;&quot;</span> + name + <span class="string">&#x27;\&#x27;&#x27;</span> +</span><br><span class="line">                <span class="string">&quot;, age=&quot;</span> + age +</span><br><span class="line">                <span class="string">&quot;, register=&quot;</span> + register +</span><br><span class="line">                <span class="string">&#x27;&#125;&#x27;</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="储藏类"><a href="#储藏类" class="headerlink" title="储藏类"></a>储藏类</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.trey.repository;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.trey.entity.Student;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.sql.*;</span><br><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">StudentRepository</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> List&lt;Student&gt; <span class="title function_">findAll</span><span class="params">()</span>&#123;</span><br><span class="line">        ArrayList&lt;Student&gt; list = <span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;&gt;();</span><br><span class="line">        <span class="type">Connection</span> <span class="variable">connection</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">        <span class="type">PreparedStatement</span> <span class="variable">preparedStatement</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">        <span class="type">ResultSet</span> <span class="variable">resultSet</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            Class.forName(<span class="string">&quot;com.mysql.jdbc.Driver&quot;</span>);</span><br><span class="line">            <span class="type">String</span> <span class="variable">url</span> <span class="operator">=</span> <span class="string">&quot;jdbc:mysql://1.1.1.3:3306/bookdb?useUnicode=true&amp;characterEncoding=UTF-8&quot;</span>;</span><br><span class="line">            <span class="type">String</span> <span class="variable">user</span> <span class="operator">=</span> <span class="string">&quot;root&quot;</span>;</span><br><span class="line">            <span class="type">String</span> <span class="variable">password</span> <span class="operator">=</span> <span class="string">&quot;Passwd123&quot;</span>;</span><br><span class="line">            connection = DriverManager.getConnection(url,user,password);</span><br><span class="line">            <span class="type">String</span> <span class="variable">sql</span> <span class="operator">=</span> <span class="string">&quot;select * from user;&quot;</span>;</span><br><span class="line">            preparedStatement = connection.prepareStatement(sql);</span><br><span class="line">            resultSet = preparedStatement.executeQuery();</span><br><span class="line">            <span class="type">Student</span> <span class="variable">student</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">            <span class="keyword">while</span> (resultSet.next()) &#123;</span><br><span class="line">                <span class="type">int</span> <span class="variable">id</span> <span class="operator">=</span> resultSet.getInt(<span class="number">1</span>);</span><br><span class="line">                <span class="type">String</span> <span class="variable">name</span> <span class="operator">=</span> resultSet.getString(<span class="number">2</span>);</span><br><span class="line">                <span class="type">double</span> <span class="variable">age</span> <span class="operator">=</span> resultSet.getDouble(<span class="number">3</span>);</span><br><span class="line">                <span class="type">Date</span> <span class="variable">date</span> <span class="operator">=</span> resultSet.getDate(<span class="number">4</span>);</span><br><span class="line">                student = <span class="keyword">new</span> <span class="title class_">Student</span>(id, name, age, date);</span><br><span class="line">                list.add(student);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">catch</span> (ClassNotFoundException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125; <span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">            <span class="keyword">try</span> &#123;</span><br><span class="line">                connection.close();</span><br><span class="line">                preparedStatement.close();</span><br><span class="line">                resultSet.close();</span><br><span class="line">            &#125; <span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">                e.printStackTrace();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> list;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        <span class="type">StudentRepository</span> <span class="variable">studentRepository</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">StudentRepository</span>();</span><br><span class="line">        System.out.println(studentRepository.findAll());</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="控制类"><a href="#控制类" class="headerlink" title="控制类"></a>控制类</h4><p>jsp接收数据，还需要两个包： jstl.jar 和standard.jar </p>
<p>(我下载好了，放到了 D:\install\apache-tomcat-8.5.78-windows-x64\jakarta-taglibs-standard-1.1.2 ）</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.trey.servlet;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.trey.entity.Student;</span><br><span class="line"><span class="keyword">import</span> com.trey.repository.StudentRepository;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> javax.servlet.ServletException;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.annotation.WebServlet;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServlet;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletRequest;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletResponse;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="meta">@WebServlet(&quot;/student&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">StudentServlet</span> <span class="keyword">extends</span> <span class="title class_">HttpServlet</span> &#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">doGet</span><span class="params">(HttpServletRequest req, HttpServletResponse resp)</span> <span class="keyword">throws</span> ServletException, IOException &#123;</span><br><span class="line">        <span class="comment">//返回试图+数据</span></span><br><span class="line">        <span class="type">StudentRepository</span> <span class="variable">studentRepository</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">StudentRepository</span>();</span><br><span class="line">        List&lt;Student&gt; list = studentRepository.findAll();</span><br><span class="line">        System.out.println(list);</span><br><span class="line">        req.setAttribute(<span class="string">&quot;list&quot;</span>,list);                           <span class="comment">//数据</span></span><br><span class="line">        req.getRequestDispatcher(<span class="string">&quot;index.jsp&quot;</span>).forward(req,resp); <span class="comment">//视图</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">doPost</span><span class="params">(HttpServletRequest req, HttpServletResponse resp)</span> <span class="keyword">throws</span> ServletException, IOException &#123;</span><br><span class="line">        <span class="built_in">super</span>.doPost(req, resp);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="试图index-jsp"><a href="#试图index-jsp" class="headerlink" title="试图index.jsp"></a>试图index.jsp</h4><figure class="highlight jsp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">&lt;%--</span><br><span class="line">  Created by IntelliJ IDEA.</span><br><span class="line">  User: Lenovo</span><br><span class="line">  Date: <span class="number">2022</span>/<span class="number">5</span>/<span class="number">22</span></span><br><span class="line">  Time: <span class="number">17</span>:<span class="number">23</span></span><br><span class="line">  To change <span class="built_in">this</span> template use File | Settings | File Templates.</span><br><span class="line">--%&gt;</span><br><span class="line">&lt;%@ page contentType=<span class="string">&quot;text/html;charset=UTF-8&quot;</span> language=<span class="string">&quot;java&quot;</span> %&gt;</span><br><span class="line">&lt;%@ taglib prefix=<span class="string">&quot;c&quot;</span> uri=<span class="string">&quot;http://java.sun.com/jsp/jstl/core&quot;</span> %&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">  &lt;head&gt;</span><br><span class="line">    &lt;title&gt;$Title$&lt;/title&gt;</span><br><span class="line">  &lt;/head&gt;</span><br><span class="line">  &lt;body&gt;</span><br><span class="line">  &lt;h1&gt;学生管理系统&lt;/h1&gt;</span><br><span class="line">  &lt;table&gt;</span><br><span class="line">    &lt;th&gt;编号&lt;/th&gt;</span><br><span class="line">    &lt;th&gt;姓名&lt;/th&gt;</span><br><span class="line">    &lt;th&gt;成绩&lt;/th&gt;</span><br><span class="line">    &lt;th&gt;注册日期&lt;/th&gt;</span><br><span class="line">    &lt;c:forEach items=<span class="string">&quot;$&#123;list&#125;&quot;</span> <span class="keyword">var</span>=<span class="string">&quot;student&quot;</span>&gt;</span><br><span class="line">      &lt;tr&gt;</span><br><span class="line">        &lt;td&gt;$&#123;student.id&#125;&lt;/td&gt;</span><br><span class="line">        &lt;td&gt;$&#123;student.name&#125;&lt;/td&gt;</span><br><span class="line">        &lt;td&gt;$&#123;student.age&#125;&lt;/td&gt;</span><br><span class="line">        &lt;td&gt;$&#123;student.register&#125;&lt;/td&gt;</span><br><span class="line">      &lt;/tr&gt;</span><br><span class="line">    &lt;/c:forEach&gt;</span><br><span class="line">  &lt;/table&gt;</span><br><span class="line">  &lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="查询功能完成"><a href="#查询功能完成" class="headerlink" title="查询功能完成"></a>查询功能完成</h4><p>启动项目</p>
<p>打开网页 ： <a target="_blank" rel="noopener" href="http://1.1.1.1:8080/student">http://1.1.1.1:8080/student</a></p>
<p>学生管理系统查询结果</p>
<table>
<thead>
<tr>
<th>编号</th>
<th>姓名</th>
<th>成绩</th>
<th>注册日期</th>
</tr>
</thead>
<tbody><tr>
<td>5</td>
<td>张三</td>
<td>36.0</td>
<td>2022-05-22</td>
</tr>
<tr>
<td>6</td>
<td>李四</td>
<td>36.0</td>
<td>2022-05-22</td>
</tr>
<tr>
<td>7</td>
<td>王五</td>
<td>36.0</td>
<td>2022-05-22</td>
</tr>
</tbody></table>
<h2 id="java-增加-mysql"><a href="#java-增加-mysql" class="headerlink" title="java 增加 mysql"></a>java 增加 mysql</h2><h4 id="新建add-jsp"><a href="#新建add-jsp" class="headerlink" title="新建add.jsp"></a>新建add.jsp</h4><p>​	在web下面新建</p>
<figure class="highlight jsp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&lt;%@ page contentType=<span class="string">&quot;text/html;charset=UTF-8&quot;</span> language=<span class="string">&quot;java&quot;</span> %&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">    &lt;title&gt;添加记录&lt;/title&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">    &lt;form action=<span class="string">&quot;/student&quot;</span> method=<span class="string">&quot;post&quot;</span>&gt;</span><br><span class="line">        姓名：&lt;input type=<span class="string">&quot;text&quot;</span> name=<span class="string">&quot;name&quot;</span>/&gt;&lt;br/&gt;</span><br><span class="line">        成绩：&lt;input type=<span class="string">&quot;text&quot;</span> name=<span class="string">&quot;age&quot;</span>/&gt;&lt;br/&gt;</span><br><span class="line">        &lt;input type=<span class="string">&quot;submit&quot;</span> value=<span class="string">&quot;提交&quot;</span>&gt;</span><br><span class="line">    &lt;/form&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure>

<h4 id="实现储藏类Repository的add方法"><a href="#实现储藏类Repository的add方法" class="headerlink" title="实现储藏类Repository的add方法"></a>实现储藏类Repository的add方法</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">add</span><span class="params">(String name,Double age)</span>&#123;</span><br><span class="line">        <span class="type">Connection</span> <span class="variable">connection</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">        <span class="type">PreparedStatement</span> <span class="variable">preparedStatement</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            Class.forName(<span class="string">&quot;com.mysql.jdbc.Driver&quot;</span>);</span><br><span class="line">            <span class="type">String</span> <span class="variable">url</span> <span class="operator">=</span> <span class="string">&quot;jdbc:mysql://1.1.1.3:3306/bookdb?useUnicode=true&amp;characterEncoding=UTF-8&quot;</span>;</span><br><span class="line">            <span class="type">String</span> <span class="variable">user</span> <span class="operator">=</span> <span class="string">&quot;root&quot;</span>;</span><br><span class="line">            <span class="type">String</span> <span class="variable">password</span> <span class="operator">=</span> <span class="string">&quot;Passwd123&quot;</span>;</span><br><span class="line">            connection = DriverManager.getConnection(url,user,password);</span><br><span class="line">            <span class="type">String</span> <span class="variable">sql</span> <span class="operator">=</span> <span class="string">&quot;insert into user(name,age,register) values (?,?,?)&quot;</span>;</span><br><span class="line">            preparedStatement = connection.prepareStatement(sql);</span><br><span class="line">            preparedStatement.setString(<span class="number">1</span>,name);</span><br><span class="line">            preparedStatement.setDouble(<span class="number">2</span>,age);</span><br><span class="line">            preparedStatement.setDate(<span class="number">3</span>,<span class="keyword">new</span> <span class="title class_">Date</span>(System.currentTimeMillis()));</span><br><span class="line">            preparedStatement.executeUpdate();</span><br><span class="line">        &#125; <span class="keyword">catch</span> (ClassNotFoundException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125; <span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">            <span class="keyword">try</span> &#123;</span><br><span class="line">                connection.close();</span><br><span class="line">                preparedStatement.close();</span><br><span class="line">            &#125; <span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">                e.printStackTrace();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<h4 id="实现Servlet的doPost方法"><a href="#实现Servlet的doPost方法" class="headerlink" title="实现Servlet的doPost方法"></a>实现Servlet的doPost方法</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">doPost</span><span class="params">(HttpServletRequest req, HttpServletResponse resp)</span> <span class="keyword">throws</span> ServletException, IOException &#123;</span><br><span class="line">    <span class="comment">//处理汉字乱码方法1，此方法中把req转化成UTF-8编码</span></span><br><span class="line">    req.setCharacterEncoding(<span class="string">&quot;UTF-8&quot;</span>);</span><br><span class="line">    <span class="comment">//处理汉字乱码方法2，过滤器</span></span><br><span class="line">    <span class="comment">//CharacterFilter.java</span></span><br><span class="line">    <span class="comment">//读取表单数据</span></span><br><span class="line">    <span class="type">String</span> <span class="variable">name</span> <span class="operator">=</span> req.getParameter(<span class="string">&quot;name&quot;</span>);</span><br><span class="line">    <span class="type">String</span> <span class="variable">ageStr</span> <span class="operator">=</span> req.getParameter(<span class="string">&quot;age&quot;</span>);</span><br><span class="line">    <span class="type">Double</span> <span class="variable">age</span> <span class="operator">=</span> Double.parseDouble(ageStr);</span><br><span class="line">    <span class="comment">//执行insert</span></span><br><span class="line">    studentRepository.add(name,age);</span><br><span class="line">    <span class="comment">//返回重定向到查询页面</span></span><br><span class="line">    resp.sendRedirect(<span class="string">&quot;/student&quot;</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="过滤器"><a href="#过滤器" class="headerlink" title="过滤器"></a>过滤器</h2><p>注明：选中类名ctrl+i实现接口 。  如果什么都不写，就统统拦截</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.trey.filter;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> javax.servlet.*;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.annotation.WebFilter;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"></span><br><span class="line"><span class="comment">//拦截</span></span><br><span class="line"><span class="meta">@WebFilter(&quot;/student&quot;)</span></span><br><span class="line"><span class="comment">//实现Filter接口</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">CharacterFilter</span> <span class="keyword">implements</span> <span class="title class_">Filter</span> &#123;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">init</span><span class="params">(FilterConfig filterConfig)</span> <span class="keyword">throws</span> ServletException &#123;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">doFilter</span><span class="params">(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)</span> <span class="keyword">throws</span> IOException, ServletException &#123;</span><br><span class="line">        servletRequest.setCharacterEncoding(<span class="string">&quot;UTF-8&quot;</span>);</span><br><span class="line">        filterChain.doFilter(servletRequest,servletResponse);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">destroy</span><span class="params">()</span> &#123;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="优化-JDBCTools-提取封装"><a href="#优化-JDBCTools-提取封装" class="headerlink" title="优化 JDBCTools 提取封装"></a>优化 JDBCTools 提取封装</h2><h4 id="新建包类-JDBCTools"><a href="#新建包类-JDBCTools" class="headerlink" title="新建包类 JDBCTools"></a>新建包类 JDBCTools</h4><p>包 ： com.trey.tuil</p>
<p>类 ： JDBCTools</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.trey.util;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.sql.*;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">JDBCTools</span> &#123;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> Connection connection;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="type">String</span> <span class="variable">url</span> <span class="operator">=</span> <span class="string">&quot;jdbc:mysql://1.1.1.3:3306/bookdb?useUnicode=true&amp;characterEncoding=UTF-8&quot;</span>;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="type">String</span> <span class="variable">user</span> <span class="operator">=</span> <span class="string">&quot;root&quot;</span>;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="type">String</span> <span class="variable">password</span> <span class="operator">=</span> <span class="string">&quot;Passwd123&quot;</span>;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">static</span> &#123;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            Class.forName(<span class="string">&quot;com.mysql.jdbc.Driver&quot;</span>);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (ClassNotFoundException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> Connection <span class="title function_">getConnection</span><span class="params">()</span>&#123;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            connection = DriverManager.getConnection(url,user,password);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> connection;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">release</span><span class="params">(Connection connection, Statement statement, ResultSet resultSet)</span>&#123;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="keyword">if</span> (connection != <span class="literal">null</span>) &#123;</span><br><span class="line">                connection.close();</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (statement != <span class="literal">null</span>) &#123;</span><br><span class="line">                statement.close();</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (resultSet != <span class="literal">null</span>) &#123;</span><br><span class="line">                resultSet.close();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="修改Repository储藏类"><a href="#修改Repository储藏类" class="headerlink" title="修改Repository储藏类"></a>修改Repository储藏类</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.trey.repository;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.trey.entity.Student;</span><br><span class="line"><span class="keyword">import</span> com.trey.util.JDBCTools;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.sql.*;</span><br><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"><span class="keyword">import</span> java.util.Currency;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">StudentRepository</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> List&lt;Student&gt; <span class="title function_">findAll</span><span class="params">()</span>&#123;</span><br><span class="line">        ArrayList&lt;Student&gt; list = <span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;&gt;();</span><br><span class="line">        <span class="type">Connection</span> <span class="variable">connection</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">        <span class="type">PreparedStatement</span> <span class="variable">preparedStatement</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">        <span class="type">ResultSet</span> <span class="variable">resultSet</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            connection = JDBCTools.getConnection();</span><br><span class="line">            <span class="type">String</span> <span class="variable">sql</span> <span class="operator">=</span> <span class="string">&quot;select * from user;&quot;</span>;</span><br><span class="line">            preparedStatement = connection.prepareStatement(sql);</span><br><span class="line">            resultSet = preparedStatement.executeQuery();</span><br><span class="line">            <span class="type">Student</span> <span class="variable">student</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">            <span class="keyword">while</span> (resultSet.next()) &#123;</span><br><span class="line">                <span class="type">int</span> <span class="variable">id</span> <span class="operator">=</span> resultSet.getInt(<span class="number">1</span>);</span><br><span class="line">                <span class="type">String</span> <span class="variable">name</span> <span class="operator">=</span> resultSet.getString(<span class="number">2</span>);</span><br><span class="line">                <span class="type">double</span> <span class="variable">age</span> <span class="operator">=</span> resultSet.getDouble(<span class="number">3</span>);</span><br><span class="line">                <span class="type">Date</span> <span class="variable">date</span> <span class="operator">=</span> resultSet.getDate(<span class="number">4</span>);</span><br><span class="line">                student = <span class="keyword">new</span> <span class="title class_">Student</span>(id, name, age, date);</span><br><span class="line">                list.add(student);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;  <span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">            JDBCTools.release(connection, preparedStatement, resultSet);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> list;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        <span class="type">StudentRepository</span> <span class="variable">studentRepository</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">StudentRepository</span>();</span><br><span class="line">        System.out.println(studentRepository.findAll());</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">add</span><span class="params">(String name,Double age)</span>&#123;</span><br><span class="line">        <span class="type">Connection</span> <span class="variable">connection</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">        <span class="type">PreparedStatement</span> <span class="variable">preparedStatement</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            connection = JDBCTools.getConnection();</span><br><span class="line">            <span class="type">String</span> <span class="variable">sql</span> <span class="operator">=</span> <span class="string">&quot;insert into user(name,age,register) values (?,?,?)&quot;</span>;</span><br><span class="line">            preparedStatement = connection.prepareStatement(sql);</span><br><span class="line">            preparedStatement.setString(<span class="number">1</span>,name);</span><br><span class="line">            preparedStatement.setDouble(<span class="number">2</span>,age);</span><br><span class="line">            preparedStatement.setDate(<span class="number">3</span>,<span class="keyword">new</span> <span class="title class_">Date</span>(System.currentTimeMillis()));</span><br><span class="line">            preparedStatement.executeUpdate();</span><br><span class="line">        &#125;  <span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">            JDBCTools.release(connection,preparedStatement,<span class="literal">null</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="java-删除-mysql"><a href="#java-删除-mysql" class="headerlink" title="java 删除 mysql"></a>java 删除 mysql</h2><h4 id="修改index-jsp-提供页面操作入口"><a href="#修改index-jsp-提供页面操作入口" class="headerlink" title="修改index.jsp (提供页面操作入口)"></a>修改index.jsp (提供页面操作入口)</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">&lt;table&gt;</span><br><span class="line">    &lt;th&gt;编号&lt;/th&gt;</span><br><span class="line">    &lt;th&gt;姓名&lt;/th&gt;</span><br><span class="line">    &lt;th&gt;成绩&lt;/th&gt;</span><br><span class="line">    &lt;th&gt;注册日期&lt;/th&gt;</span><br><span class="line">    &lt;th&gt;操作&lt;/th&gt;</span><br><span class="line">    &lt;c:forEach items=&quot;$&#123;list&#125;&quot; var=&quot;student&quot;&gt;</span><br><span class="line">      &lt;tr&gt;</span><br><span class="line">        &lt;td&gt;$&#123;student.id&#125;&lt;/td&gt;</span><br><span class="line">        &lt;td&gt;$&#123;student.name&#125;&lt;/td&gt;</span><br><span class="line">        &lt;td&gt;$&#123;student.age&#125;&lt;/td&gt;</span><br><span class="line">        &lt;td&gt;$&#123;student.register&#125;&lt;/td&gt;</span><br><span class="line">        &lt;td&gt;</span><br><span class="line">          &lt;a href=&quot;/student?method=delete&amp;id=$&#123;student.id&#125;&quot;&gt;删除&lt;/a&gt;</span><br><span class="line">          &lt;a&gt;修改&lt;/a&gt;</span><br><span class="line">        &lt;/td&gt;</span><br><span class="line">      &lt;/tr&gt;</span><br><span class="line">    &lt;/c:forEach&gt;</span><br><span class="line">  &lt;/table&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="修改Servlet控制区分get请求"><a href="#修改Servlet控制区分get请求" class="headerlink" title="修改Servlet控制区分get请求"></a>修改Servlet控制区分get请求</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line">   <span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">doGet</span><span class="params">(HttpServletRequest req, HttpServletResponse resp)</span> <span class="keyword">throws</span> ServletException, IOException &#123;</span><br><span class="line">       <span class="type">String</span> <span class="variable">method</span> <span class="operator">=</span> req.getParameter(<span class="string">&quot;method&quot;</span>);</span><br><span class="line">       <span class="keyword">if</span> (method == <span class="literal">null</span>) &#123;</span><br><span class="line">           method = <span class="string">&quot;findAll&quot;</span>;</span><br><span class="line">       &#125;</span><br><span class="line">       <span class="keyword">switch</span> (method) &#123;</span><br><span class="line">           <span class="keyword">case</span> <span class="string">&quot;findAll&quot;</span>:</span><br><span class="line">               <span class="comment">//返回试图+数据</span></span><br><span class="line">               List&lt;Student&gt; list = studentRepository.findAll();</span><br><span class="line">               req.setAttribute(<span class="string">&quot;list&quot;</span>,list);                           <span class="comment">//数据</span></span><br><span class="line">               req.getRequestDispatcher(<span class="string">&quot;index.jsp&quot;</span>).forward(req,resp); <span class="comment">//视图</span></span><br><span class="line">               <span class="keyword">break</span>;</span><br><span class="line">           <span class="keyword">case</span> <span class="string">&quot;delete&quot;</span>:</span><br><span class="line">               <span class="type">String</span> <span class="variable">idStr</span> <span class="operator">=</span> req.getParameter(<span class="string">&quot;id&quot;</span>);</span><br><span class="line">               <span class="type">int</span> <span class="variable">id</span> <span class="operator">=</span> Integer.parseInt(idStr);</span><br><span class="line">               studentRepository.deleteById(id);</span><br><span class="line">               resp.sendRedirect(<span class="string">&quot;/student&quot;</span>);</span><br><span class="line">               <span class="keyword">break</span>;</span><br><span class="line">       &#125;</span><br><span class="line">   &#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="实现储藏类delete方法"><a href="#实现储藏类delete方法" class="headerlink" title="实现储藏类delete方法"></a>实现储藏类delete方法</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">deleteById</span><span class="params">(Integer id)</span>&#123;</span><br><span class="line">     <span class="type">Connection</span> <span class="variable">connection</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">     <span class="type">PreparedStatement</span> <span class="variable">preparedStatement</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">     connection = JDBCTools.getConnection();</span><br><span class="line">     <span class="type">String</span> <span class="variable">sql</span> <span class="operator">=</span> <span class="string">&quot;delete from user where id = ?&quot;</span>;</span><br><span class="line">     <span class="keyword">try</span> &#123;</span><br><span class="line">         preparedStatement = connection.prepareStatement(sql);</span><br><span class="line">         preparedStatement.setInt(<span class="number">1</span>,id);</span><br><span class="line">         preparedStatement.executeUpdate();</span><br><span class="line">     &#125; <span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">         e.printStackTrace();</span><br><span class="line">     &#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">         JDBCTools.release(connection, preparedStatement, <span class="literal">null</span>);</span><br><span class="line">     &#125;</span><br><span class="line"> &#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="java-修改-mysql"><a href="#java-修改-mysql" class="headerlink" title="java 修改 mysql"></a>java 修改 mysql</h2><h4 id="修改index-jsp-提供页面操作入口-取id"><a href="#修改index-jsp-提供页面操作入口-取id" class="headerlink" title="修改index.jsp(提供页面操作入口) 取id"></a>修改index.jsp(提供页面操作入口) 取id</h4> <figure class="highlight jsp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">&lt;h1&gt;学生管理系统&lt;/h1&gt;</span><br><span class="line">&lt;table&gt;</span><br><span class="line">  &lt;th&gt;编号&lt;/th&gt;</span><br><span class="line">  &lt;th&gt;姓名&lt;/th&gt;</span><br><span class="line">  &lt;th&gt;成绩&lt;/th&gt;</span><br><span class="line">  &lt;th&gt;注册日期&lt;/th&gt;</span><br><span class="line">  &lt;th&gt;操作&lt;/th&gt;</span><br><span class="line">  &lt;c:forEach items=<span class="string">&quot;$&#123;list&#125;&quot;</span> <span class="keyword">var</span>=<span class="string">&quot;student&quot;</span>&gt;</span><br><span class="line">    &lt;tr&gt;</span><br><span class="line">      &lt;td&gt;$&#123;student.id&#125;&lt;/td&gt;</span><br><span class="line">      &lt;td&gt;$&#123;student.name&#125;&lt;/td&gt;</span><br><span class="line">      &lt;td&gt;$&#123;student.age&#125;&lt;/td&gt;</span><br><span class="line">      &lt;td&gt;$&#123;student.register&#125;&lt;/td&gt;</span><br><span class="line">      &lt;td&gt;</span><br><span class="line">        &lt;a href=<span class="string">&quot;/student?method=deleteById&amp;id=$&#123;student.id&#125;&quot;</span>&gt;删除&lt;/a&gt;</span><br><span class="line">        &lt;a href=<span class="string">&quot;/student?method=findById&amp;id=$&#123;student.id&#125;&quot;</span>&gt;修改&lt;/a&gt;</span><br><span class="line">      &lt;/td&gt;</span><br><span class="line">    &lt;/tr&gt;</span><br><span class="line">  &lt;/c:forEach&gt;</span><br><span class="line">&lt;/table&gt;</span><br><span class="line">  &lt;a href=<span class="string">&quot;add.jsp&quot;</span>&gt;添加&lt;/a&gt;&lt;br/&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="根据id取出Student对象"><a href="#根据id取出Student对象" class="headerlink" title="根据id取出Student对象"></a>根据id取出Student对象</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">@Override</span><br><span class="line">   protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException &#123;</span><br><span class="line">       String method = req.getParameter(&quot;method&quot;);</span><br><span class="line">       if (method == null) &#123;</span><br><span class="line">           method = &quot;findAll&quot;;</span><br><span class="line">       &#125;</span><br><span class="line">       switch (method) &#123;</span><br><span class="line">           case &quot;findAll&quot;:</span><br><span class="line">               //返回试图+数据</span><br><span class="line">               List&lt;Student&gt; list = studentRepository.findAll();</span><br><span class="line">               req.setAttribute(&quot;list&quot;,list);                           //数据</span><br><span class="line">               req.getRequestDispatcher(&quot;selectAll.jsp&quot;).forward(req,resp); //视图</span><br><span class="line">               break;</span><br><span class="line">           case &quot;deleteById&quot;:</span><br><span class="line">               String idStr = req.getParameter(&quot;id&quot;);</span><br><span class="line">               int id = Integer.parseInt(idStr);</span><br><span class="line">               studentRepository.deleteById(id);</span><br><span class="line">               resp.sendRedirect(&quot;/student&quot;);</span><br><span class="line">               break;</span><br><span class="line">           case &quot;findById&quot;:</span><br><span class="line">               idStr = req.getParameter(&quot;id&quot;);</span><br><span class="line">               id = Integer.parseInt(idStr);</span><br><span class="line">               req.setAttribute(&quot;student&quot;,studentRepository.findById(id));</span><br><span class="line">               req.getRequestDispatcher(&quot;update.jsp&quot;).forward(req,resp);</span><br><span class="line">               break;</span><br><span class="line">       &#125;</span><br><span class="line">   &#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="根据Student对象填写update-jsp页面"><a href="#根据Student对象填写update-jsp页面" class="headerlink" title="根据Student对象填写update.jsp页面"></a>根据Student对象填写update.jsp页面</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&lt;body&gt;</span><br><span class="line">    &lt;h1&gt;修改记录&lt;/h1&gt;</span><br><span class="line">    &lt;form action=&quot;/student&quot; method=&quot;post&quot;&gt;</span><br><span class="line">        编号：&lt;input type=&quot;text&quot; name=&quot;id&quot; value=&quot;$&#123;student.id&#125;&quot; readonly/&gt;&lt;br/&gt;</span><br><span class="line">        姓名：&lt;input type=&quot;text&quot; name=&quot;name&quot; value=&quot;$&#123;student.name&#125;&quot;/&gt;&lt;br/&gt;</span><br><span class="line">        成绩：&lt;input type=&quot;text&quot; name=&quot;age&quot; value=&quot;$&#123;student.age&#125;&quot;/&gt;&lt;br/&gt;</span><br><span class="line">        成绩：&lt;input type=&quot;text&quot; name=&quot;age&quot; value=&quot;$&#123;student.register &#125;&quot; readonly/&gt;&lt;br/&gt;</span><br><span class="line">        &lt;input type=&quot;hidden&quot; name=&quot;method&quot; value=&quot;update&quot;/&gt;</span><br><span class="line">        &lt;input type=&quot;submit&quot; value=&quot;修改&quot;&gt;</span><br><span class="line">    &lt;/form&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="修改update-jsp里面的值"><a href="#修改update-jsp里面的值" class="headerlink" title="修改update.jsp里面的值"></a>修改update.jsp里面的值</h4><p>​		网页操作，修改</p>
<h4 id="将新值传入update-sql语句，并执行，并返回新全表数据页面"><a href="#将新值传入update-sql语句，并执行，并返回新全表数据页面" class="headerlink" title="将新值传入update.sql语句，并执行，并返回新全表数据页面"></a>将新值传入update.sql语句，并执行，并返回新全表数据页面</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">doPost</span><span class="params">(HttpServletRequest req, HttpServletResponse resp)</span> <span class="keyword">throws</span> ServletException, IOException &#123;</span><br><span class="line">     <span class="type">String</span> <span class="variable">method</span> <span class="operator">=</span> req.getParameter(<span class="string">&quot;method&quot;</span>);</span><br><span class="line">     <span class="keyword">switch</span> (method) &#123;</span><br><span class="line">         <span class="keyword">case</span> <span class="string">&quot;update&quot;</span>:</span><br><span class="line">             <span class="type">String</span> <span class="variable">idStr</span> <span class="operator">=</span> req.getParameter(<span class="string">&quot;id&quot;</span>);</span><br><span class="line">             <span class="type">int</span> <span class="variable">id</span> <span class="operator">=</span> Integer.parseInt(idStr);</span><br><span class="line">             name = req.getParameter(<span class="string">&quot;name&quot;</span>);</span><br><span class="line">             ageStr = req.getParameter(<span class="string">&quot;age&quot;</span>);</span><br><span class="line">             age = Double.parseDouble(ageStr);</span><br><span class="line">             studentRepository.update(id,name,age);</span><br><span class="line">             <span class="comment">//返回重定向到查询页面</span></span><br><span class="line">             resp.sendRedirect(<span class="string">&quot;/student&quot;</span>);</span><br><span class="line">             <span class="keyword">break</span>;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="执行update-sql语句"><a href="#执行update-sql语句" class="headerlink" title="执行update.sql语句"></a>执行update.sql语句</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">void</span>  <span class="title function_">update</span><span class="params">(Integer id, String name, Double age)</span>&#123;</span><br><span class="line">      <span class="type">Connection</span> <span class="variable">connection</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">      <span class="type">PreparedStatement</span> <span class="variable">preparedStatement</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">      <span class="keyword">try</span> &#123;</span><br><span class="line">          connection = JDBCTools.getConnection();</span><br><span class="line">          <span class="type">String</span> <span class="variable">sql</span> <span class="operator">=</span> <span class="string">&quot;update user set name = ? , age = ? , register = ? where id = ?&quot;</span>;</span><br><span class="line">          preparedStatement = connection.prepareStatement(sql);</span><br><span class="line">          preparedStatement.setString(<span class="number">1</span>,name);</span><br><span class="line">          preparedStatement.setDouble(<span class="number">2</span>,age);</span><br><span class="line">          preparedStatement.setDate(<span class="number">3</span>,<span class="keyword">new</span> <span class="title class_">Date</span>(System.currentTimeMillis()));</span><br><span class="line">          preparedStatement.setInt(<span class="number">4</span>,id);</span><br><span class="line">          preparedStatement.executeUpdate();</span><br><span class="line">      &#125;  <span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">          e.printStackTrace();</span><br><span class="line">      &#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">          JDBCTools.release(connection,preparedStatement,<span class="literal">null</span>);</span><br><span class="line">      &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="后续汇总"><a href="#后续汇总" class="headerlink" title="后续汇总"></a>后续汇总</h2><p><img src="C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\1653302798049.png" alt="1653302798049"></p>
<h1 id="informix报错情况"><a href="#informix报错情况" class="headerlink" title="informix报错情况"></a>informix报错情况</h1><h2 id="数据库没有启动"><a href="#数据库没有启动" class="headerlink" title="数据库没有启动"></a>数据库没有启动</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">java.sql.SQLException: com.gbasedbt.asf.IfxASFException: Attempt to connect to database server (g31) failed.</span><br><span class="line">	at com.gbasedbt.jdbc.IfxSqliConnect.&lt;init&gt;(IfxSqliConnect.java:1611)</span><br><span class="line">	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)</span><br><span class="line">	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)</span><br><span class="line">	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)</span><br><span class="line">	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="字符集不匹配"><a href="#字符集不匹配" class="headerlink" title="字符集不匹配"></a>字符集不匹配</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">java.sql.SQLException: Unable to load locale categories.</span><br><span class="line">	at com.gbasedbt.jdbc.IfxSqliConnect.&lt;init&gt;(IfxSqliConnect.java:1436)</span><br><span class="line">	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)</span><br><span class="line">	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)</span><br><span class="line">	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)</span><br><span class="line">	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="表不存在"><a href="#表不存在" class="headerlink" title="表不存在"></a>表不存在</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">java.sql.SQLException: com.gbasedbt.asf.IfxASFException: Attempt to connect to database server (g31) failed.</span><br><span class="line">	at com.gbasedbt.jdbc.IfxSqliConnect.&lt;init&gt;(IfxSqliConnect.java:1611)</span><br><span class="line">	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)</span><br><span class="line">	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)</span><br><span class="line">	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)</span><br><span class="line">	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="insert语句中出现非法字符"><a href="#insert语句中出现非法字符" class="headerlink" title="insert语句中出现非法字符"></a>insert语句中出现非法字符</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">环境 dbvis DB字符集gbk</span></span><br><span class="line">jdbc:gbasedbt-sqli://1.1.1.3:9031/gbk:GBASEDBTSERVER=g31;DB_LOCALE=zh_CN.GB18030-2000;CLIENT_LOCALE=zh_CN.GB18030-2000;NEWCODESET=utf8,GB18030-2000,5488;IFX_LOCK_MODE_WAIT=30</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">语句</span></span><br><span class="line">insert into user(name,age) values(&#x27;汪&#x27;,1);    --这一句报错</span><br><span class="line">insert into user(name,age) values(&#x27;伟&#x27;,1);    --这一句报错</span><br><span class="line">insert into user(name,age) values(&#x27;汪伟&#x27;,1);  --这一句不报错</span><br><span class="line">这里的报错和报错说明，utf8-&gt;gb18030的字符转换有问题。</span><br><span class="line">如果此时关闭过滤器，那么java中insert就不会报错，插入的汪是：c3 a6 c2 b1 c2 aa</span><br><span class="line">汪 utf8： e6 b1 aa 对应字符 f 1 *</span><br><span class="line">汪 gbk ： cd f4    对应字符 M t</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">报错</span></span><br><span class="line">[Code: -202, SQL State: IX000]  An illegal character has been found in the statement.</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">处理：把NEWCODESET设置为jbk即可，但是这f样如果之前入口的数据库是utf8的就存在不一致编码数据</span></span><br><span class="line">jdbc:gbasedbt-sqli://1.1.1.3:9031/gbk:GBASEDBTSERVER=g31;DB_LOCALE=zh_CN.GB18030-2000;CLIENT_LOCALE=zh_CN.GB18030-2000;NEWCODESET=GB18030,GB18030-2000,5488;IFX_LOCK_MODE_WAIT=30</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="Java里面也会遇到insert语句中出现非法字符"><a href="#Java里面也会遇到insert语句中出现非法字符" class="headerlink" title="Java里面也会遇到insert语句中出现非法字符"></a>Java里面也会遇到insert语句中出现非法字符</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">java.sql.SQLException: An illegal character has been found in the statement.</span><br><span class="line">	at com.gbasedbt.util.IfxErrMsg.getSQLException(IfxErrMsg.java:408)</span><br><span class="line">	at com.gbasedbt.jdbc.IfxSqli.a(IfxSqli.java:3572)</span><br><span class="line">	at com.gbasedbt.jdbc.IfxSqli.D(IfxSqli.java:3852)</span><br><span class="line">	at com.gbasedbt.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2738)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="Java里面遇到了不能解码的数据select语句"><a href="#Java里面遇到了不能解码的数据select语句" class="headerlink" title="Java里面遇到了不能解码的数据select语句"></a>Java里面遇到了不能解码的数据select语句</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">java.sql.SQLException: Encoding or code set not supported.</span><br><span class="line">	at com.gbasedbt.util.IfxErrMsg.getSQLException(IfxErrMsg.java:408)</span><br><span class="line">	at com.gbasedbt.jdbc.IfxVarChar.fromIfx(IfxVarChar.java:195)</span><br><span class="line">	at com.gbasedbt.jdbc.IfxRowColumn.a(IfxRowColumn.java:335)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="字符集不存在"><a href="#字符集不存在" class="headerlink" title="字符集不存在"></a>字符集不存在</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">Error -23101 Unable to load locale categories</span><br><span class="line"></span><br><span class="line">当设置的 DB_LOCALE 和 CLIENT_LOCALE 的字符集对应的以下文件不存在时，出现该错误。</span><br><span class="line"></span><br><span class="line">    - $InformixDIR/gls/lc11/DB_LOCALE&#x27;s( 语言 _ 地区 )/(db 的 16 进制编码 ).lco</span><br><span class="line">    - $InformixDIR/gls/lc11/CLIENT_LOCALE&#x27;s( 语言 _ 地区 )/( db 的 16 进制编码 ).lco</span><br><span class="line">    - $InformixDIR/gls/lc11/CLIENT_LOCALE&#x27;s( 语言 _ 地区 )/( client 的 16 进制编码 ).lco</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="字符集不能转换"><a href="#字符集不能转换" class="headerlink" title="字符集不能转换"></a>字符集不能转换</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">Error -23104 Error opening required code-set conversion object file</span><br><span class="line"></span><br><span class="line">当设置的 DB_LOCALE 和 CLIENT_LOCALE 的字符集对应的以下转换文件不存在时，会出现该错误。当然只有当 DB_LOCALE 和 CLIENT_LOCALE 的字符集不一致时才会需要转换，如果一致则不会出现 -23104 错误。</span><br><span class="line"></span><br><span class="line"> - $InformixDIR/gls/cv9/ccccdddd.cvo </span><br><span class="line"> - $InformixDIR/gls/cv9/ddddcccc.cvo</span><br><span class="line"></span><br><span class="line">其中：cccc 为 CLIENT_LOCALE 字符集编码对应的 16 进制值</span><br><span class="line"></span><br><span class="line">dddd 为 DB_LOCALE 字符集编码对应的 16 进制值</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="字符集DB-LOCALE不匹配"><a href="#字符集DB-LOCALE不匹配" class="headerlink" title="字符集DB_LOCALE不匹配"></a>字符集DB_LOCALE不匹配</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">Error -23197 Database locale information mismatch</span><br><span class="line"></span><br><span class="line">当出现如下情况时，出现 -23197 错误。</span><br><span class="line"></span><br><span class="line">    定义的 DB_LOCALE 值与数据库的使用的值（数据库创建时使用的 DB_LOCALE 值）不一致；</span><br><span class="line">    通过 SET COLLATION 语句定义 DB_LOCALE 值与数据库的使用值不一致 ;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="字符集存在非法字符"><a href="#字符集存在非法字符" class="headerlink" title="字符集存在非法字符"></a>字符集存在非法字符</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">Error -201，-202 数据库提示语法错误</span><br><span class="line"></span><br><span class="line">Error -201，-202 数据库提示语法错误，不支持中文对象名，如中文表名、字段别名、视图名。该类错误提示原因是当前数据库的 DB_LOCALE 设置问题。</span><br><span class="line"></span><br><span class="line">如果数据库的 DB_LOCALE 设置为 zh_cn.GB18030-2000，则数据库就可以支持中文对象名。</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h1 id="Servlet-JSP-JDBC-把库换成GBasedb8s"><a href="#Servlet-JSP-JDBC-把库换成GBasedb8s" class="headerlink" title="Servlet + JSP + JDBC 把库换成GBasedb8s"></a>Servlet + JSP + JDBC 把库换成GBasedb8s</h1><h2 id="informix-创建user表"><a href="#informix-创建user表" class="headerlink" title="informix 创建user表"></a>informix 创建user表</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> IF <span class="keyword">EXISTS</span> <span class="keyword">user</span>;</span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> <span class="keyword">user</span>  (</span><br><span class="line">  id  serial <span class="keyword">not</span> <span class="keyword">null</span> ,</span><br><span class="line">  name <span class="type">varchar</span>(<span class="number">9</span>) <span class="keyword">not</span> <span class="keyword">null</span>,</span><br><span class="line">  age <span class="type">int</span>,</span><br><span class="line">  register datetime <span class="keyword">year</span> <span class="keyword">to</span> <span class="keyword">second</span>,</span><br><span class="line">  <span class="keyword">PRIMARY</span> KEY (id) </span><br><span class="line">) extent size <span class="number">64</span> next size <span class="number">128</span> </span><br><span class="line">;</span><br><span class="line"></span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> <span class="keyword">user</span>(name,age,register) <span class="keyword">values</span>(<span class="string">&#x27;张三&#x27;</span>,<span class="number">36</span>,<span class="string">&#x27;2022-05-22 08:00:00&#x27;</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> <span class="keyword">user</span>(name,age,register) <span class="keyword">values</span>(<span class="string">&#x27;李四&#x27;</span>,<span class="number">36</span>,<span class="string">&#x27;2022-05-22 08:00:00&#x27;</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> <span class="keyword">user</span>(name,age,register) <span class="keyword">values</span>(<span class="string">&#x27;王五&#x27;</span>,<span class="number">36</span>,<span class="string">&#x27;2022-05-22 08:00:00&#x27;</span>);</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="新建JDBCToolsGBase类"><a href="#新建JDBCToolsGBase类" class="headerlink" title="新建JDBCToolsGBase类"></a>新建JDBCToolsGBase类</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.trey.util;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.sql.*;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">JDBCToolsGBase</span> &#123;</span><br><span class="line">        <span class="keyword">private</span> <span class="keyword">static</span> Connection connection;</span><br><span class="line">        <span class="comment">//DB是utf8库编码</span></span><br><span class="line">        <span class="comment">//DB_LOCALE=zh_CN.utf8</span></span><br><span class="line">        <span class="comment">//dbs_dbsname  utf8</span></span><br><span class="line">        <span class="comment">//dbs_collate  zh_CN.57372</span></span><br><span class="line">        <span class="keyword">private</span> <span class="keyword">static</span> <span class="type">String</span> <span class="variable">urlutf8</span> <span class="operator">=</span> <span class="string">&quot;jdbc:gbasedbt-sqli://1.1.1.3:9031/utf8:GBASEDBTSERVER=g31;DB_LOCALE=zh_CN.utf8;CLIENT_LOCALE=zh_CN.utf8;IFX_LOCK_MODE_WAIT=30&quot;</span>;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//DB是819库编码</span></span><br><span class="line">        <span class="comment">//DB_LOCALE=en_US.819</span></span><br><span class="line">        <span class="comment">//dbs_dbsname  sysmaster</span></span><br><span class="line">        <span class="comment">//dbs_collate  en_US.819</span></span><br><span class="line">        <span class="keyword">private</span> <span class="keyword">static</span> <span class="type">String</span> <span class="variable">url819utf8</span> <span class="operator">=</span> <span class="string">&quot;jdbc:gbasedbt-sqli://1.1.1.3:9031/sysmaster:GBASEDBTSERVER=g31;DB_LOCALE=en_US.819;NEWCODESET=utf8,8859-1,819;IFX_LOCK_MODE_WAIT=30&quot;</span>;</span><br><span class="line">        <span class="keyword">private</span> <span class="keyword">static</span> <span class="type">String</span> <span class="variable">url819gbk</span> <span class="operator">=</span> <span class="string">&quot;jdbc:gbasedbt-sqli://1.1.1.3:9031/sysmaster:GBASEDBTSERVER=g31;DB_LOCALE=en_US.819;NEWCODESET=GB18030-2000,8859-1,819;IFX_LOCK_MODE_WAIT=30&quot;</span>;</span><br><span class="line">        <span class="comment">//DB是gbk库编码</span></span><br><span class="line">        <span class="comment">//DB_LOCALE=zh_CN.GB18030-2000</span></span><br><span class="line">        <span class="comment">//dbs_dbsname  gbk</span></span><br><span class="line">        <span class="comment">//dbs_collate  zh_CN.5488</span></span><br><span class="line">        <span class="comment">//这样可以正常处理utf8终端插入的汉字,再次证明解铃还须系铃人，NEWCODESET=jdk编码集.校验字符集.校验字符编号。</span></span><br><span class="line">        <span class="comment">// （注意这时如果关闭过滤器：会出现页面insert的数据是乱码的问题，应为这时页面以gbk的数据把数据存入了gbk的库，但是你读取的时候又把jbk的数据转成了utf8）</span></span><br><span class="line">        <span class="comment">// （后来发现如果关闭过滤器，插入如的数据，是什么编码，情况比上面我说的还要复杂，它并不是gbk，也不是utf8.他1个汉字就占6个字符。）</span></span><br><span class="line">        <span class="comment">//private static String urlgbk = &quot;jdbc:gbasedbt-sqli://1.1.1.3:9031/gbk:GBASEDBTSERVER=g31;DB_LOCALE=zh_CN.GB18030-2000;CLIENT_LOCALE=zh_CN.GB18030-2000;NEWCODESET=utf8,GB18030-2000,5488;IFX_LOCK_MODE_WAIT=30&quot;;</span></span><br><span class="line">        <span class="comment">//而这样可以正常处理gbk终端插入的汉字,正确。</span></span><br><span class="line">        <span class="comment">//private static String urlgbk = &quot;jdbc:gbasedbt-sqli://1.1.1.3:9031/gbk:GBASEDBTSERVER=g31;DB_LOCALE=zh_CN.GB18030-2000;CLIENT_LOCALE=zh_CN.GB18030-2000;NEWCODESET=GB18030,GB18030-2000,5488;IFX_LOCK_MODE_WAIT=30&quot;;</span></span><br><span class="line">        <span class="comment">//NEWCODESET可以省略</span></span><br><span class="line">        <span class="keyword">private</span> <span class="keyword">static</span> <span class="type">String</span> <span class="variable">urlgbk</span> <span class="operator">=</span> <span class="string">&quot;jdbc:gbasedbt-sqli://1.1.1.3:9031/gbk:GBASEDBTSERVER=g31;DB_LOCALE=zh_CN.GB18030-2000;CLIENT_LOCALE=zh_CN.GB18030-2000;IFX_LOCK_MODE_WAIT=30&quot;</span>;</span><br><span class="line">        <span class="comment">//一句话： NEWCODESET的第一个字段是你的数据存储表中的编码，它等于你的终端的编码，或者说它等于你的jdk的编码。</span></span><br><span class="line">        <span class="comment">//两句话： 我们平常说的数据库的字符集，其实准确的说是数据库校验字符集，它是做校验的，它不是实际存储的表的字符集。</span></span><br><span class="line">        <span class="comment">//三句话： 推荐校验字符集和终端字符集保持统一字符集，那么就不需要NEWCODESET了。</span></span><br><span class="line">        <span class="comment">//四句话： 为了防止终端字符集把不同的数据编码存入表中，可以开启NEWCODESET，它保证了读写表的字符集。</span></span><br><span class="line">        <span class="comment">//五句话： 如果没有设置NEWCODESET那么，默认终端或jdk保证了表的字符集。</span></span><br><span class="line">        <span class="comment">//最后一句： 过滤器不能关，关了表里的编码很乱。要保证过滤器的字符集和校验字符集一致，这样就避免了NEWCODESET的校验，这样就不会遇到&#x27;汪&#x27;字不能插入的问题。（入库时的校验只是为了出库时的正常，并不实际转换。）</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">private</span> <span class="keyword">static</span> <span class="type">String</span> <span class="variable">user</span> <span class="operator">=</span> <span class="string">&quot;gbasedbt&quot;</span>;</span><br><span class="line">        <span class="keyword">private</span> <span class="keyword">static</span> <span class="type">String</span> <span class="variable">password</span> <span class="operator">=</span> <span class="string">&quot;GBase123&quot;</span>;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">static</span> &#123;</span><br><span class="line">            <span class="keyword">try</span> &#123;</span><br><span class="line">                Class.forName(<span class="string">&quot;com.gbasedbt.jdbc.Driver&quot;</span>);</span><br><span class="line">            &#125; <span class="keyword">catch</span> (ClassNotFoundException e) &#123;</span><br><span class="line">                e.printStackTrace();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">static</span> Connection <span class="title function_">getConnection</span><span class="params">()</span>&#123;</span><br><span class="line">            <span class="keyword">try</span> &#123;</span><br><span class="line">                <span class="comment">//connection = DriverManager.getConnection(urlutf8,user,password);</span></span><br><span class="line">                <span class="comment">//connection = DriverManager.getConnection(url819,user,password);</span></span><br><span class="line">                connection = DriverManager.getConnection(urlgbk,user,password);</span><br><span class="line">            &#125; <span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">                e.printStackTrace();</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> connection;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">release</span><span class="params">(Connection connection, Statement statement, ResultSet resultSet)</span>&#123;</span><br><span class="line">            <span class="keyword">try</span> &#123;</span><br><span class="line">                <span class="keyword">if</span> (connection != <span class="literal">null</span>) &#123;</span><br><span class="line">                    connection.close();</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">if</span> (statement != <span class="literal">null</span>) &#123;</span><br><span class="line">                    statement.close();</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">if</span> (resultSet != <span class="literal">null</span>) &#123;</span><br><span class="line">                    resultSet.close();</span><br><span class="line">                &#125;</span><br><span class="line">            &#125; <span class="keyword">catch</span> (SQLException e) &#123;</span><br><span class="line">                e.printStackTrace();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="把储藏类连接数据可类换成此类即可"><a href="#把储藏类连接数据可类换成此类即可" class="headerlink" title="把储藏类连接数据可类换成此类即可"></a>把储藏类连接数据可类换成此类即可</h2><p>​		简单省略</p>
<h1 id="INFOMRIX-和-JDK的字符集设置"><a href="#INFOMRIX-和-JDK的字符集设置" class="headerlink" title="INFOMRIX 和 JDK的字符集设置"></a>INFOMRIX 和 JDK的字符集设置</h1><h2 id="创建utf8编码的数据库"><a href="#创建utf8编码的数据库" class="headerlink" title="创建utf8编码的数据库"></a>创建utf8编码的数据库</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">export DB_LOCALE=zh_CN.utf8</span><br><span class="line">export CLIENT_LOCALE=zh_CN.utf8</span><br><span class="line">echo &quot;create database gbk in datadbs01 with log;&quot; |dbaccess sysmaster </span><br><span class="line">echo &quot;select * from sysdbslocale;&quot; |dbaccess sysmaster </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="创建gbk编码的数据库"><a href="#创建gbk编码的数据库" class="headerlink" title="创建gbk编码的数据库"></a>创建gbk编码的数据库</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">export DB_LOCALE=zh_CN.GB18030-2000</span><br><span class="line">export CLIENT_LOCALE=zh_CN.GB18030-2000</span><br><span class="line">echo &quot;create database gbk in datadbs01 with log;&quot; |dbaccess sysmaster </span><br><span class="line">echo &quot;select * from sysdbslocale;&quot; |dbaccess sysmaster </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="我java项目用的是utf8编码"><a href="#我java项目用的是utf8编码" class="headerlink" title="我java项目用的是utf8编码"></a>我java项目用的是utf8编码</h2><p>​		见上文过滤器</p>
<h2 id="informix-GLS-编码和转换"><a href="#informix-GLS-编码和转换" class="headerlink" title="informix GLS 编码和转换"></a>informix GLS 编码和转换</h2><h3 id="编码对照表-注册registry"><a href="#编码对照表-注册registry" class="headerlink" title="编码对照表-注册registry"></a>编码对照表-注册registry</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">InformixDIR=/opt/gbase330</span><br><span class="line">cat $InformixDIR/gls/cm3/registry    #查看 GLS 字符名称、编码对照表。</span><br><span class="line">gbasedbt:g31[/opt/gbase330/gls]$cat $InformixDIR/gls/cm3/registry |grep 18030</span><br><span class="line">gbasedbt:g31[/opt/gbase330/gls]$cat $InformixDIR/gls/cm3/registry |grep -i utf8</span><br><span class="line">gbasedbt:g31[/opt/gbase330/gls]$cat $InformixDIR/gls/cm3/registry |grep -i e00d</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">结果</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">字符集名称  	编码  	十六进制编码</span></span><br><span class="line">GB18030-2000    5488    # 0x1570 Simplified Chinese GB18030-2000</span><br><span class="line">utf8            57372   # 0xe01c 注意：utf8是72</span><br><span class="line">gb              57357   # 0xe00d 注意：  gb是57</span><br><span class="line">GB2312-80       57357   # 0xe00d</span><br><span class="line">cp936           57357   # 0xe00d Simplified Chinese Microsoft Windows </span><br><span class="line">Guobiao2312     57357   # 0xe00d</span><br><span class="line">gbasedbt:g31[/opt/gbase330/gls]$</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="一个字符集可以有多个名称"><a href="#一个字符集可以有多个名称" class="headerlink" title="一个字符集可以有多个名称"></a>一个字符集可以有多个名称</h3><p>​		 GLS 环境中不同字符集名称可能对应同一个字符集编码，但一个字符集只能有一个编码，也就是说字符集编码才是唯一的。 </p>
<h3 id="字符集存放在不同的目录"><a href="#字符集存放在不同的目录" class="headerlink" title="字符集存放在不同的目录"></a>字符集存放在不同的目录</h3><p>​		GLS 环境中按照语言和地区把所支持的字符集分成不同的目录。$InformixDIR&#x2F;gls&#x2F;lc11&#x2F; 语言 _ 地区 &#x2F;，如中文大陆地区的目录为：$InformixDIR&#x2F;gls&#x2F;lc11&#x2F;zh_cn&#x2F;，该目录下有如下两个文件：1570.lco e00d.lco ，说明我们在设置字符集时，我们可以使用 zh_cn.GB18030-2000 zh_cn.gb zh_cn.GB2312-80 三个不同的名称。这里（zh_cn.gb 与 zh_cn.GB2312-80 对应相同的字符集）。</p>
<h3 id="那些字符集直接可以转换"><a href="#那些字符集直接可以转换" class="headerlink" title="那些字符集直接可以转换"></a>那些字符集直接可以转换</h3><p>​		 GLS 环境中不同的字符集可以正确的进行转换，查看那些字符集可以正确转换的方法，查看目录 $InformixDIR&#x2F;gls&#x2F;cv9  目录下的是否存在指定字符集互相转换的文件。如该目录下有文件 e01ce00d.cvo 和 e00de01c.cvo 两个文件，表示 GLS  通过这两个转换文件支持 UTF-8 与 GB 之间的字符转换。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">InformixDIR=/opt/gbase330</span><br><span class="line">ls -l $InformixDIR/gls/cv9</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看utf8可以转换成那些字符集</span></span><br><span class="line">ls -l $InformixDIR/gls/cv9 |grep &#x27; e01c&#x27;</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看那些字符集可以转换成utf8</span></span><br><span class="line">ls -l $InformixDIR/gls/cv9 |grep &#x27;e01c\.&#x27;</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看utf8和GB18030-2000能否相互转换(注明：可以)</span></span><br><span class="line">ls -l $InformixDIR/gls/cv9 |grep &#x27;e01c&#x27;|grep &#x27;1570&#x27; </span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看utf8和gb能否相互转换(注明：可以)</span></span><br><span class="line">ls -l $InformixDIR/gls/cv9 |grep &#x27;e01c&#x27;|grep &#x27;e00d&#x27;  </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="DB-LOCALE-和-CLIENT-LOCALE"><a href="#DB-LOCALE-和-CLIENT-LOCALE" class="headerlink" title="DB_LOCALE 和 CLIENT_LOCALE"></a>DB_LOCALE 和 CLIENT_LOCALE</h3><p>Informix 通过 DB_LOCALE 和 CLIENT_LOCALE 来设置数据库的语言本地化支持设置。DB_LOCALE 和 CLIENT_LOCALE 的值由四部分组成 ( 第 4 部分为可选 )，字符集不区分大小写。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">   1          2            3          4 </span><br><span class="line">&lt; 语言 &gt;_&lt; 国家和地区 &gt;.&lt; 字符集名 / 字符集编码 &gt;[@modifier]</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>举例说明 :</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">CLIENT_LOCALE=en_us.8859-1 </span><br><span class="line">CLIENT_LOCALE=en_us.819 </span><br><span class="line"># 以上两个为同一字符集：819 为 8859-1 的编码</span><br><span class="line">DB_LOCALE=zh_cn.gb</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="DB-LOCALE-环境变量用途"><a href="#DB-LOCALE-环境变量用途" class="headerlink" title="DB_LOCALE 环境变量用途"></a>DB_LOCALE 环境变量用途</h4><ol>
<li>在客户机应用程序和数据库服务器交换字符数据时，如果 DB_LOCALE 环境变量（在客户机计算机上）的值与 CLIENT_LOCALE 的值不同，客户机应用程序将执行代码集转换。 代码集转换防止这两种代码集不同时发生数据破坏。</li>
<li>在客户机应用程序请求连接时，它将包括 DB_LOCALE（如果已设置）的信息发送至数据库服务器。</li>
<li>在确定如何设置服务器处理语言环境的数据库信息时，数据库服务器使用 DB_LOCALE。</li>
<li>在客户机应用程序尝试打开数据库时，数据库服务器将客户机应用程序传递的 DB_LOCALE 环境变量的值与数据库中存储的数据库语言环境进行比较。</li>
<li>当数据库服务器存取与语言环境相关的数据类型的列时，数据库服务器使用 DB_LOCALE 指定的语言环境。</li>
<li>当数据库服务器创建新数据库时，它将检查数据库语言环境（DB_LOCALE），以确定如何在数据库的系统目录中存储字符信息。此信息包括诸如如何处理正则表达式、比较字符串以及确保代码集的正确使用的操作。</li>
</ol>
<h4 id="CLIENT-LOCALE-环境变量用途"><a href="#CLIENT-LOCALE-环境变量用途" class="headerlink" title="CLIENT_LOCALE 环境变量用途"></a>CLIENT_LOCALE 环境变量用途</h4><ol>
<li>在客户机应用程序和数据库服务器交换字符数据时，如果 CLIENT_LOCALE 环境变量的代码集与 DB_LOCALE（在客户机计算机上）的代码集不同，客户机应用程序将执行代码集转换。代码集转换防止这两种代码集不同时发生数据破坏。</li>
<li>在客户机应用程序请求连接时，它将包括 CLIENT_LOCALE 的信息发送至数据库服务器。</li>
<li>在确定如何设置服务器处理语言环境的客户机应用程序信息时，数据库服务器将使用 CLIENT_LOCALE。</li>
<li>在 Informix ESQL&#x2F;C 的预处理器处理源文件时，它接受以 CLIENT_LOCALE 的代码集编写的 C 源代码。 在  Informix ESQL&#x2F;C 客户机应用程序执行时，将检查 CLIENT_LOCALE  以获得客户机语言环境的名称，该语言环境将对操作系统文件名、文本文件的内容以及日期、时间和数字数据的格式产生影响。</li>
<li>在数据库实用程序创建文件时，文件名和文件内容位于 CLIENT_LOCALE 指定的代码集中。在查找特定于产品的消息文件时，客户机应用程序将检查与客户机语言环境关联的消息目录。</li>
</ol>
<h3 id="客户机应用程序代码集转换"><a href="#客户机应用程序代码集转换" class="headerlink" title="客户机应用程序代码集转换"></a>客户机应用程序代码集转换</h3><p>当以下两个条件都为真时，客户机应用程序自动在客户机和数据库代码集之间执行代码集转换：</p>
<ul>
<li>客户机和数据库语言环境的代码集不匹配。</li>
<li>客户机和数据库代码集之间的转换存在有效的目标代码集转换。</li>
</ul>
<p>客户机应用程序开始执行时，它会比较客户机和数据库语言环境的名称，以确定是否执行代码集转换。如果设置了 CLIENT_LOCALE 和  DB_LOCALE 环境变量，那么客户机应用程序使用这些语言环境名称来分别确定客户机和数据库的代码集。如果未设置  CLIENT_LOCALE（且未设置 DBNLS），那么客户机应用程序假定客户机语言环境为缺省语言环境。如果未设置 DB_LOCALE（且未设置 DBNLS），那么客户机应用程序假定数据库语言环境与客户机语言环境（CLIENT_LOCALE 设置的值）相同。</p>
<p>​		CLIENT_LOCALE( 未设置将采用默认 en_us.819)；</p>
<p>​		DB_LOCALE( 未设置则不发送，默认与CLIENT_LOCALE设置的值相同 )</p>
<h3 id="时间格式问题"><a href="#时间格式问题" class="headerlink" title="时间格式问题"></a>时间格式问题</h3><p>Informix 数据库的时间格式由数据库服务器端环境变量 GL_DATE GL_DATETIME 控制，默认的字符集下默认的时间格式为：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">GL_DATE=&quot;%m/%d/%iy&quot; </span><br><span class="line">DATETIME=&quot;%iY-%m-%d %H:%M:%S&quot;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>但是，当我们设置了 DB_LOCALE 为 zh_cn.gb 的情形下，而没有设置 GL_DATE,DATETIME，则时间格式会采用  CLIENT_LOCALE 的值，在 zh_cn.gb 情况下，会出现：“2009 年 10 月 2  日”的日期格式，如果我们之前系统采用默认的时间格式的情况下，就会出现时间格式不匹配的错误。如果我们仍然需要采用默认的时间格式，我们需要在数据库服务端修改时间格式环境变量即可：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">GL_DATE=&quot;%m/%d/%iy&quot; </span><br><span class="line">DATETIME=&quot;%iY-%m-%d %H:%M:%S&quot;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="换成unicode"><a href="#换成unicode" class="headerlink" title="换成unicode"></a>换成unicode</h3><p>数据库不能够脱离字符集独立存在，它一定属于某种字符集。</p>
<p>CSDK2.7 版本，IDS 默认情况下使用 Garbage In, Garbage Out 模式处理中文字符，若数据库服务器上的  DB_LOCALE 采用默认的 en_us.8859-1 字符集，能够正常支持中文字符。但是升级到 CSDK2.8 及以上版本时，不再支持  Garbage In, Garbage Out  模式，将出现乱码问题。iso-8859_1字符集的数据库只支持单字节。虽然可以往里面保存多字节的数据，但是数据库本身只是简单的认为这些数据只是单字节的数据。无论你存入的是双字节的中文，还是4字节的unicode数据，数据库本身只是把它当为单字节而已。</p>
<p>客户端通过jdbc连接上数据库，并提取数据后，数据按照数据库默认的编码方式被提取到客户端。客户端要将其转换成unicode。因为jdbc是基于java的，而java内部全部是unicode编码。那么在客户端进行转换的时候，就有问题了，到底按哪种格式转？</p>
<p>如果保存在数据库中的数据都是iso-8859_1中包含的字符，那么这样操作没错。但是如果是数据中有中文，那么这样操作就错了。</p>
<p>例如，汉字“中文”的ascii码为0xD6 0xD0 0xCE  0xC4,而常用的汉字codeset为cp936。如果按照cp936转unicode,则转换的结果是0xE4 0xB8 0xAD 0xE6  0x96 0x87;如果按照iso-8859_1转换则结果是0xC3 0x96 0xC3 0x90 0xC3 0x8E 0xC3 0x84.</p>
<p>你看，同样的数据，就是因为指定不同的原始字符集，导致转换成unicode的时候，结果截然不同。所以在用jdbc连接数据库的时候，有必要把这个转换关系给说清楚。</p>
<p>在informix jdbc中是通过newcodeset来说明问题的。</p>
<p>在这里，我们就要说清楚，数据库是按什么字符集存放数据的，取到客户端java时，这些数据<strong>需要按照什么样的字符集转换成unicode。</strong></p>
<p>再或者更改数据库的字符集（设置 DB_LOCALE&#x3D;zh_cn.GB18030-2000，重新创建数据库），然后按本文中描述的方法进行  DB_LOCALE 与 CLIENT_LOCALE 的设置方法进行处理。若在实际环境下重建数据库成本太高，可以考虑如下步骤进行解决 ODBC  支持中文的问题。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">数据库服务器端：</span><br><span class="line"> 1. 设置环境变量： IFMX_UNDOC_B168163=1 </span><br><span class="line"> 2. 将 en_us.8859-1 字符集文件拷贝到 zh_cn 目录下</span><br><span class="line">     cd $INFORMIXDIR/gls/lc11 </span><br><span class="line">     cp ./en_us/0333.lco ./zh_cn </span><br><span class="line"> 3. 重新启动 IDS </span><br><span class="line">客户端：</span><br><span class="line">设置语言环境：</span><br><span class="line">     l DB_LOCALE=zh_cn.GB18030-2000 </span><br><span class="line">     l CLIENT_LOCALE=zh_cn.GB18030-2000</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p> 对于 JDBC 我们可以通过 NEWCODESET 来解决该问题： </p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">newcodeset的格式如下：</span><br><span class="line">newcodeset=jdk codeset, ifx codeset,ifx codenum</span><br><span class="line"></span><br><span class="line">jdbc的URL链接信息如下：</span><br><span class="line"></span><br><span class="line">URLString = <span class="string">&quot;jdbc:Informix-sqli://9.125.66.130:6346/dbname:InformixSERVER=servername; NEWCODESET=GB18030-2000,8859-1,819; CLIENT_LOCALE=en_US.8859-1; DB_LOCALE=en_US.8859-1;&quot;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>





<h2 id="数据库编码对照表-和-jdbc-url"><a href="#数据库编码对照表-和-jdbc-url" class="headerlink" title="数据库编码对照表 和 jdbc-url"></a>数据库编码对照表 和 jdbc-url</h2><table>
<thead>
<tr>
<th>环境变量DB_LOCALE</th>
<th>DB名称</th>
<th>DB校对dbs_collate</th>
<th>NEWCODESET</th>
<th></th>
</tr>
</thead>
<tbody><tr>
<td>zh_CN.utf8</td>
<td>utf8</td>
<td>zh_CN.57372</td>
<td>可以空 utf8,utf8,57372<br/>强换 GB18030-2000,utf8,57372</td>
<td></td>
</tr>
<tr>
<td>en_US.819</td>
<td>sysmaster</td>
<td>en_US.819</td>
<td>不能空 utf8,8859-1,819 <br/>或  GB18030-2000,8859-1,819</td>
<td></td>
</tr>
<tr>
<td>zh_CN.GB18030-2000</td>
<td>gbk</td>
<td>zh_CN.5488</td>
<td>可以空GB18030-2000,GB18030-2000,5488 <br/>强转utf8,GB18030-2000,5488</td>
<td></td>
</tr>
</tbody></table>
<h3 id="强制转换对Java的要求"><a href="#强制转换对Java的要求" class="headerlink" title="强制转换对Java的要求"></a>强制转换对Java的要求</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">servletRequest.setCharacterEncoding(<span class="string">&quot;UTF-8&quot;</span>);</span><br><span class="line">filterChain.doFilter(servletRequest,servletResponse);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="utf8-8859-1-GB18030"><a href="#utf8-8859-1-GB18030" class="headerlink" title="utf8 + 8859-1 + GB18030"></a>utf8 + 8859-1 + GB18030</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">static</span> <span class="type">String</span> <span class="variable">urlutf8</span> <span class="operator">=</span> <span class="string">&quot;jdbc:gbasedbt-sqli://1.1.1.3:9031/utf8:GBASEDBTSERVER=g31;DB_LOCALE=zh_CN.utf8;CLIENT_LOCALE=zh_CN.utf8;IFX_LOCK_MODE_WAIT=30&quot;</span>;</span><br><span class="line"><span class="keyword">private</span> <span class="keyword">static</span> <span class="type">String</span> <span class="variable">urlutf8gbk</span> <span class="operator">=</span> <span class="string">&quot;jdbc:gbasedbt-sqli://1.1.1.3:9031/utf8:GBASEDBTSERVER=g31;DB_LOCALE=zh_CN.utf8;CLIENT_LOCALE=zh_CN.utf8;NEWCODESET=GB18030-2000,utf8,57372;IFX_LOCK_MODE_WAIT=30&quot;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">private</span> <span class="keyword">static</span> <span class="type">String</span> <span class="variable">url819utf8</span> <span class="operator">=</span> <span class="string">&quot;jdbc:gbasedbt-sqli://1.1.1.3:9031/sysmaster:GBASEDBTSERVER=g31;DB_LOCALE=en_US.819;NEWCODESET=utf8,8859-1,819;IFX_LOCK_MODE_WAIT=30&quot;</span>;</span><br><span class="line"><span class="keyword">private</span> <span class="keyword">static</span> <span class="type">String</span> <span class="variable">url819gbk</span> <span class="operator">=</span> <span class="string">&quot;jdbc:gbasedbt-sqli://1.1.1.3:9031/sysmaster:GBASEDBTSERVER=g31;DB_LOCALE=en_US.819;NEWCODESET=GB18030-2000,8859-1,819;IFX_LOCK_MODE_WAIT=30&quot;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">private</span> <span class="keyword">static</span> <span class="type">String</span> <span class="variable">urlgbk</span> <span class="operator">=</span> <span class="string">&quot;jdbc:gbasedbt-sqli://1.1.1.3:9031/gbk:GBASEDBTSERVER=g31;DB_LOCALE=zh_CN.GB18030-2000;CLIENT_LOCALE=zh_CN.GB18030-2000;IFX_LOCK_MODE_WAIT=30&quot;</span>;</span><br><span class="line"><span class="keyword">private</span> <span class="keyword">static</span> <span class="type">String</span> <span class="variable">urlgbkutf8</span> <span class="operator">=</span> <span class="string">&quot;jdbc:gbasedbt-sqli://1.1.1.3:9031/gbk:GBASEDBTSERVER=g31;DB_LOCALE=zh_CN.GB18030-2000;CLIENT_LOCALE=zh_CN.GB18030-2000;NEWCODESET=utf8,GB18030-2000,5488;IFX_LOCK_MODE_WAIT=30&quot;</span>;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="字符转换测试小结"><a href="#字符转换测试小结" class="headerlink" title="字符转换测试小结"></a>字符转换测试小结</h3><pre><code>    //一句话： NEWCODESET的第一个字段是JDK存取数据的编码，它等于你的终端的编码，或者说它等于你的jdk的编码。
    //两句话： 我们平常说的数据库的字符集，其实准确的说是数据库校验字符集，它是做校验的，它尽量是实际存储的表的字符集。
    //三句话： 推荐校验字符集和终端字符集保持统一字符集，那么就不需要NEWCODESET了。
    //四句话： 为了防止终端字符集把不同的数据编码存入表中，可以开启NEWCODESET，但要三个字段相同。
    //五句话： 如果没有设置NEWCODESET那么，默认终端或jdk字符集。
    //最后一句： 过滤器不能关，关了表里的编码很乱。要保证过滤器的字符集和校验字符集一致，这样就避免了NEWCODESET的校验，这样就不会遇到&#39;汪&#39;字不能插入的问题。（入库时的校验只是为了出库时的正常，值校验并不实际转换。）
</code></pre>
<h3 id="这种报错就是jdk的编码和jdbc里面设置的NEWCODESET的校验码不一致"><a href="#这种报错就是jdk的编码和jdbc里面设置的NEWCODESET的校验码不一致" class="headerlink" title="这种报错就是jdk的编码和jdbc里面设置的NEWCODESET的校验码不一致"></a>这种报错就是jdk的编码和jdbc里面设置的NEWCODESET的校验码不一致</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">java.sql.SQLException: An illegal character has been found in the statement.</span><br><span class="line">	at com.gbasedbt.util.IfxErrMsg.getSQLException(IfxErrMsg.java:<span class="number">408</span>)</span><br><span class="line">	at com.gbasedbt.jdbc.IfxSqli.a(IfxSqli.java:<span class="number">3572</span>)</span><br><span class="line">	at com.gbasedbt.jdbc.IfxSqli.D(IfxSqli.java:<span class="number">3852</span>)</span><br><span class="line">	at com.gbasedbt.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:<span class="number">273</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">        <span class="comment">//servletRequest.setCharacterEncoding(&quot;UTF-8&quot;);</span></span><br><span class="line">        servletRequest.setCharacterEncoding(<span class="string">&quot;GB18030-2000&quot;</span>);</span><br><span class="line">和</span><br><span class="line">    	<span class="comment">//NEWCODESET=utf8,GB18030-2000,5488</span></span><br><span class="line">   		NEWCODESET=GB18030-<span class="number">2000</span>,utf8,<span class="number">57372</span></span><br><span class="line">需要对应。</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>这种校验是好事， 如果你不校验，那么你的数据是什么编码会很乱，且无法维护统一编码。</p>
<p>所以很简单： </p>
<ol>
<li>来啦一个数要存，我设置了NEWCODESET,那么把这个数据从JDK中取到，把他从NEWCODE转成校验字符集给到表存储。</li>
<li>来啦一个要取数，我设置了NEWCODESET, 那么我把你存储的这个字符取出来，把他从校验字符集转换成NEWCODE给到JDK结束。</li>
<li>CLIENT_LOCALE对于jdbc不起作用，可以省略，或保持和DB_LOCLAE一致。</li>
</ol>
<h3 id="jdbc夹带用户名和密码"><a href="#jdbc夹带用户名和密码" class="headerlink" title="jdbc夹带用户名和密码"></a>jdbc夹带用户名和密码</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">String</span> <span class="variable">url</span> <span class="operator">=</span> <span class="string">&quot;jdbc:Informix-sqli://10.127.1.11:8001/testdb:</span></span><br><span class="line"><span class="string">InformixSERVER=servername;user=user;password=password;</span></span><br><span class="line"><span class="string">DB_LOCALE=zh_CN.gb;CLIENT_LOCALE=zh_CN.gb&quot;</span>;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="破坏测试-往jbk库里面插入utf8编码的数据"><a href="#破坏测试-往jbk库里面插入utf8编码的数据" class="headerlink" title="破坏测试-往jbk库里面插入utf8编码的数据"></a>破坏测试-往jbk库里面插入utf8编码的数据</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">//这样可以往jbk库里面插入utf8编码的数据：“汪伟”能插入，“汪”不能插入。</span><br><span class="line"></span><br><span class="line">jdbc:gbasedbt-sqli://1.1.1.3:9031/gbk:GBASEDBTSERVER=g31;DB_LOCALE=zh_CN.GB18030-2000;CLIENT_LOCALE=zh_CN.GB18030-2000;NEWCODESET=utf8,GB18030-2000,5488;IFX_LOCK_MODE_WAIT=30</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>







 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%9F%BA%E7%A1%80/" rel="tag">基础</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
    <article
  id="post-入门-Golang之路"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/05/10/%E5%85%A5%E9%97%A8-Golang%E4%B9%8B%E8%B7%AF/"
    >入门-Golang之路</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/05/10/%E5%85%A5%E9%97%A8-Golang%E4%B9%8B%E8%B7%AF/" class="article-date">
  <time datetime="2023-05-10T00:59:14.000Z" itemprop="datePublished">2023-05-10</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/Golang/">Golang</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h1 id="Golang之路"><a href="#Golang之路" class="headerlink" title="Golang之路"></a>Golang之路</h1><p>g</p>
<h2 id="下载"><a href="#下载" class="headerlink" title="下载"></a>下载</h2><p>​	<a target="_blank" rel="noopener" href="https://golang.google.cn/">https://golang.google.cn/</a></p>
<p>​	<a target="_blank" rel="noopener" href="https://golang.google.cn/dl/">https://golang.google.cn/dl/</a></p>
<p>​	版本： go.1.18</p>
<h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><ol>
<li>GOROOT&#x3D;D:\go1.18</li>
<li>GOPATH&#x3D;D:\gopath1.18</li>
<li>GO111MODULE&#x3D;on</li>
<li>GOPROXY&#x3D;<a target="_blank" rel="noopener" href="https://goproxy.cn,direct/">https://goproxy.cn,direct</a></li>
</ol>
<h2 id="go-mod-创建项目"><a href="#go-mod-创建项目" class="headerlink" title="go mod 创建项目"></a>go mod 创建项目</h2><ol>
<li>新建目录： D:\gopath1.18\cdr</li>
<li>进入该目录下： …</li>
<li>初始化项目：   go mod init cdr</li>
<li>下载包：   go get github.com&#x2F;gin-gonic&#x2F;gin   （下载完在这里：D:\gopath1.18\pkg\mod）</li>
<li>刷新包：  go mod tidy</li>
<li>Goland打开项目，import后根据红线提示编目index，再开始丝滑</li>
</ol>
<h2 id="gin"><a href="#gin" class="headerlink" title="gin"></a>gin</h2><p>在线文档： <a target="_blank" rel="noopener" href="https://www.itying.com/gin">https://www.itying.com/gin</a></p>
<p>我的专栏： <a target="_blank" rel="noopener" href="https://www.itying.com/category-79-b0.html">https://www.itying.com/category-79-b0.html</a></p>
<p>官网： <a target="_blank" rel="noopener" href="https://gin-gonic.com/zh-cn">https://gin-gonic.com/zh-cn</a></p>
<h3 id="gin基本结构"><a href="#gin基本结构" class="headerlink" title="gin基本结构"></a>gin基本结构</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">		r := gin.Default()</span><br><span class="line">​		r.LoadHTMLGlob(<span class="string">&quot;templates/*&quot;</span>)</span><br><span class="line">​		r.GET(<span class="string">&quot;/&quot;</span>,funcName)</span><br><span class="line"><span class="number">1.</span>GET 	 查</span><br><span class="line"><span class="number">2.</span>POST   增</span><br><span class="line"><span class="number">3.</span>PUT    改</span><br><span class="line"><span class="number">4.</span>DELETE 删</span><br><span class="line">​		funcName(c *gin.Context)&#123;	</span><br><span class="line">​			c.<span class="type">string</span>(<span class="number">200</span>,<span class="string">&quot;aaaaaaaaaaa&quot;</span>)</span><br><span class="line">​		&#125;</span><br><span class="line"><span class="number">1.</span> c.<span class="type">string</span> 返回字符串</span><br><span class="line"><span class="number">2.</span> c.json   返回json</span><br><span class="line"><span class="number">3.</span> c.jsonp  返回jsonp</span><br><span class="line"><span class="number">4.</span> c.xml    返回xml</span><br><span class="line"><span class="number">5.</span> c.html   返回网页,需要先加载模板：r.LoadHTMLGlob(<span class="string">&quot;templates/*&quot;</span>) &#123;&#123;.变量名称&#125;&#125;</span><br><span class="line">​		r.Run(<span class="string">&quot;:8080&quot;</span>)</span><br></pre></td></tr></table></figure>

<h3 id="gin模板放在不同目录里面的配置方法"><a href="#gin模板放在不同目录里面的配置方法" class="headerlink" title="gin模板放在不同目录里面的配置方法"></a>gin模板放在不同目录里面的配置方法</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//引擎</span></span><br><span class="line">r.LoadHTMLGlob(<span class="string">&quot;templates/**/*&quot;</span>)</span><br><span class="line"><span class="comment">//模板起名</span></span><br><span class="line">&#123;&#123; define <span class="string">&quot;aaa/a111.html&quot;</span> &#125;&#125;</span><br><span class="line">&#123;&#123; end &#125;&#125;</span><br><span class="line"><span class="comment">//路由方法使用模板</span></span><br><span class="line">c.html(<span class="number">200</span>,<span class="string">&quot;aaa/a111.html&quot;</span>,<span class="keyword">map</span>[<span class="type">string</span>]&#123;&#125;)</span><br></pre></td></tr></table></figure>

<h3 id="gin模板嵌套"><a href="#gin模板嵌套" class="headerlink" title="gin模板嵌套"></a>gin模板嵌套</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123;&#123; template <span class="string">&quot;aaa/a111.html&quot;</span> . &#125;&#125;</span><br></pre></td></tr></table></figure>

<h3 id="gin前端变量"><a href="#gin前端变量" class="headerlink" title="gin前端变量"></a>gin前端变量</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123;&#123; $a := .name &#125;&#125;</span><br></pre></td></tr></table></figure>

<h3 id="gin前端移除空格"><a href="#gin前端移除空格" class="headerlink" title="gin前端移除空格"></a>gin前端移除空格</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123;&#123;- .name -&#125;&#125;</span><br></pre></td></tr></table></figure>

<h3 id="gin前端比较函数"><a href="#gin前端比较函数" class="headerlink" title="gin前端比较函数"></a>gin前端比较函数</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">eq lt gt le ge ne</span><br></pre></td></tr></table></figure>

<h3 id="gin前端条件判断"><a href="#gin前端条件判断" class="headerlink" title="gin前端条件判断"></a>gin前端条件判断</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&#123;&#123; <span class="keyword">if</span> gt .score <span class="number">80</span> &#125;&#125;</span><br><span class="line">	优秀</span><br><span class="line">&#123;&#123; <span class="keyword">else</span> <span class="keyword">if</span> gt $score <span class="number">60</span> &#125;&#125;</span><br><span class="line">	及格</span><br><span class="line">&#123;&#123; <span class="keyword">else</span> &#125;&#125;</span><br><span class="line">	不及格</span><br><span class="line">&#123;&#123; end &#125;&#125;</span><br></pre></td></tr></table></figure>

<h3 id="gin前端range循环"><a href="#gin前端range循环" class="headerlink" title="gin前端range循环"></a>gin前端range循环</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&lt;dl&gt;</span><br><span class="line">	&#123;&#123; <span class="keyword">range</span> $i,$v := .obj &#125;&#125;</span><br><span class="line">		&lt;li&gt; &#123;&#123; key为$i，值为$v &#125;&#125;  &lt;/li&gt;</span><br><span class="line">	&#123;&#123; <span class="keyword">else</span> &#125;&#125;</span><br><span class="line">		a数组为空</span><br><span class="line">	&#123;&#123; end &#125;&#125;</span><br><span class="line">&lt;/dl&gt;</span><br></pre></td></tr></table></figure>

<h3 id="gin前端with解构"><a href="#gin前端with解构" class="headerlink" title="gin前端with解构"></a>gin前端with解构</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&#123;&#123; with .atype &#125;&#125;</span><br><span class="line"><span class="comment">//然后a结构体就被赋值给.了</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="gin前端预定义函数"><a href="#gin前端预定义函数" class="headerlink" title="gin前端预定义函数"></a>gin前端预定义函数</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">and , or , not , <span class="built_in">len</span> , index</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="gin自定义函数"><a href="#gin自定义函数" class="headerlink" title="gin自定义函数"></a>gin自定义函数</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">r.SetFuncMap(template.FuncMap&#123;</span><br><span class="line">    <span class="string">&quot;formatDate&quot;</span>:formatAsDate,   </span><br><span class="line">&#125;)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="gin静态文件服务"><a href="#gin静态文件服务" class="headerlink" title="gin静态文件服务"></a>gin静态文件服务</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">    r := gin.Default()</span><br><span class="line">    r.Static(<span class="string">&quot;/static&quot;</span>,<span class="string">&quot;./static&quot;</span>)</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//把程序本目录下的s目录映给s路由</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="get传值给go"><a href="#get传值给go" class="headerlink" title="get传值给go"></a>get传值给go</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">r.GET(<span class="string">&quot;/getValue&quot;</span>,<span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span>&#123;</span><br><span class="line">    username := c.Query(<span class="string">&quot;username&quot;</span>)</span><br><span class="line">    age := c.Query(<span class="string">&quot;age&quot;</span>)</span><br><span class="line">    page := c.DefaultQuery(<span class="string">&quot;page&quot;</span>,<span class="string">&quot;2&quot;</span>)</span><br><span class="line">    c.JSON(<span class="number">200</span>,gin.H&#123;</span><br><span class="line">        <span class="string">&quot;username&quot;</span> : username,</span><br><span class="line">        <span class="string">&quot;age&quot;</span> : age,</span><br><span class="line">        <span class="string">&quot;page&quot;</span> : page,</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="comment">//测试： http://1.1.1.1:8080/getValue?username=%E6%B1%AA%E4%BC%9F&amp;age=99</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="post传值给go"><a href="#post传值给go" class="headerlink" title="post传值给go"></a>post传值给go</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//去到表单页</span></span><br><span class="line">r.GET(<span class="string">&quot;/addUser&quot;</span>,<span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span>&#123;</span><br><span class="line">    c.HTML(<span class="number">200</span>,<span class="string">&quot;default/addUser.html&quot;</span>,<span class="keyword">map</span>[<span class="type">string</span>]<span class="keyword">interface</span>&#123;&#125;&#123;&#125;)</span><br><span class="line">&#125;)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 表单提交给路由 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">form</span> <span class="attr">action</span>=<span class="string">&quot;/doAddUser&quot;</span> <span class="attr">method</span>=<span class="string">&quot;post&quot;</span>&gt;</span></span><br><span class="line">    用户名：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">name</span>=<span class="string">&quot;username&quot;</span> /&gt;</span> <span class="tag">&lt;<span class="name">br</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">    密 码：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;password&quot;</span> <span class="attr">name</span>=<span class="string">&quot;password&quot;</span> /&gt;</span> <span class="tag">&lt;<span class="name">br</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;submit&quot;</span> <span class="attr">value</span>=<span class="string">&quot;提交&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">form</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//执行路由post方法,golang获取表单值</span></span><br><span class="line">r.POST(<span class="string">&quot;/doAddUser&quot;</span>, <span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span> &#123;</span><br><span class="line">	username := c.PostForm(<span class="string">&quot;username&quot;</span>)</span><br><span class="line">	password := c.PostForm(<span class="string">&quot;password&quot;</span>)</span><br><span class="line">	age := c.DefaultPostForm(<span class="string">&quot;age&quot;</span>, <span class="string">&quot;26&quot;</span>)</span><br><span class="line">	c.JSON(<span class="number">200</span>, gin.H&#123;</span><br><span class="line">		<span class="string">&quot;username&quot;</span>: username,</span><br><span class="line">		<span class="string">&quot;password&quot;</span>: password,</span><br><span class="line">		<span class="string">&quot;age&quot;</span>:      age,</span><br><span class="line">	&#125;)</span><br><span class="line">&#125;)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="get传值绑定到结构体"><a href="#get传值绑定到结构体" class="headerlink" title="get传值绑定到结构体"></a>get传值绑定到结构体</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> UserInfo <span class="keyword">struct</span>&#123;</span><br><span class="line">    Username <span class="type">string</span> <span class="string">`json:&quot;username&quot; form:&quot;username&quot;`</span></span><br><span class="line">    Password <span class="type">string</span> <span class="string">`json:&quot;password&quot; form:&quot;password&quot;`</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">r.GET(<span class="string">&quot;/getUser&quot;</span>,<span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span>&#123;</span><br><span class="line">    user := &amp;UserInfo&#123;&#125;</span><br><span class="line">    <span class="keyword">if</span> err := c.ShouldBind(&amp;user); err == <span class="literal">nil</span> &#123;</span><br><span class="line">        c.JSON(<span class="number">200</span>,user)</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        c.JSON(<span class="number">200</span>,gin.H&#123;</span><br><span class="line">            <span class="string">&quot;ERR&quot;</span> : err.Error(),</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line"><span class="comment">// 测试 ： http://1.1.1.1:8080/getUser?username=%E6%B1%AA%E4%BC%9F&amp;password=0998*aa</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="post传值绑定到结构体"><a href="#post传值绑定到结构体" class="headerlink" title="post传值绑定到结构体"></a>post传值绑定到结构体</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//去到表单页</span></span><br><span class="line">r.GET(<span class="string">&quot;/addUser&quot;</span>,<span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span>&#123;</span><br><span class="line">    c.HTML(<span class="number">200</span>,<span class="string">&quot;default/addUser.html&quot;</span>,<span class="keyword">map</span>[<span class="type">string</span>]<span class="keyword">interface</span>&#123;&#125;&#123;&#125;)</span><br><span class="line">&#125;)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- 表单提交给路由 --&gt;</span><br><span class="line">&lt;form action=&quot;/doAddUser2&quot; method=&quot;post&quot;&gt;</span><br><span class="line">    用户名：&lt;input type=&quot;text&quot; name=&quot;username&quot; /&gt; &lt;br&gt;&lt;br&gt;</span><br><span class="line">    密 码：&lt;input type=&quot;password&quot; name=&quot;password&quot; /&gt; &lt;br&gt;&lt;br&gt;</span><br><span class="line">    &lt;input type=&quot;submit&quot; value=&quot;提交&quot;&gt;</span><br><span class="line">&lt;/form&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">r.POST(<span class="string">&quot;/doAddUser2&quot;</span>,<span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span>&#123;</span><br><span class="line">    user := &amp;UserInfo&#123;&#125;</span><br><span class="line">    <span class="keyword">if</span> err := c.ShouldBind(&amp;user); err == <span class="literal">nil</span> &#123;</span><br><span class="line">        c.JSON(<span class="number">200</span>,user)</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        c.JSON(<span class="number">400</span>,gin.H&#123;</span><br><span class="line">            <span class="string">&quot;ERR&quot;</span> : err.Error(),</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="xml数据绑定到结构体"><a href="#xml数据绑定到结构体" class="headerlink" title="xml数据绑定到结构体"></a>xml数据绑定到结构体</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=<span class="string">&quot;1.0&quot;</span> encoding=<span class="string">&quot;UTF-8&quot;</span>?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">article</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">content</span> <span class="attr">type</span>=<span class="string">&quot;string&quot;</span>&gt;</span>我是张三<span class="tag">&lt;/<span class="name">content</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span> <span class="attr">type</span>=<span class="string">&quot;string&quot;</span>&gt;</span>张三<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">article</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> Article <span class="keyword">struct</span>&#123;</span><br><span class="line">    Title <span class="type">string</span> <span class="string">`json:&quot;title&quot; xml:&quot;title&quot;`</span></span><br><span class="line">    Content <span class="type">string</span> <span class="string">`json:&quot;content&quot; xml:&quot;content&quot;`</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">r.POST(<span class="string">&quot;/xml&quot;</span>,<span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span>&#123;</span><br><span class="line">    article := &amp;Article&#123;&#125;</span><br><span class="line">    xmlSliceDate,_ = c.GetRawDate() <span class="comment">//获取c.Request.Body字节流</span></span><br><span class="line">    <span class="keyword">if</span> err := xml.Unmarshal(xmlSliceDate,&amp;article); err == <span class="literal">nil</span> &#123;</span><br><span class="line">        c.JSON(<span class="number">200</span>,article)</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        c.JSON(<span class="number">400</span>,gin.H&#123;</span><br><span class="line">            <span class="string">&quot;ERR&quot;</span> : err.Error(),</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="gin动态路由"><a href="#gin动态路由" class="headerlink" title="gin动态路由"></a>gin动态路由</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">r.GET(&quot;/list/:cid&quot;, func(c *gin.Context)&#123;</span><br><span class="line">	cid := c.Param(&quot;cid&quot;)</span><br><span class="line">	c.String(200,&quot;%v&quot;,cid)</span><br><span class="line">&#125;)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="gin加载css文件和jsp文件"><a href="#gin加载css文件和jsp文件" class="headerlink" title="gin加载css文件和jsp文件"></a>gin加载css文件和jsp文件</h3><p>参考网站： <a target="_blank" rel="noopener" href="https://blog.51cto.com/dongweizhen/3606790">https://blog.51cto.com/dongweizhen/3606790</a></p>
<p>新增目录结构：</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">templates/statics/index.css</span><br><span class="line">templates/statics/index.js</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>main.go内容</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">	<span class="string">&quot;github.com/gin-gonic/gin&quot;</span></span><br><span class="line">	<span class="string">&quot;html/template&quot;</span></span><br><span class="line">	<span class="string">&quot;net/http&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">	<span class="comment">//定义一个路由</span></span><br><span class="line">	r := gin.Default()</span><br><span class="line">	<span class="comment">//加载静态文件</span></span><br><span class="line">	r.Static(<span class="string">&quot;/dwz&quot;</span>,<span class="string">&quot;templates/statics&quot;</span>)</span><br><span class="line">	<span class="comment">//添加自定义函数，解析下面的“百度一下”html代码</span></span><br><span class="line">	r.SetFuncMap(template.FuncMap&#123;</span><br><span class="line">		<span class="string">&quot;safe&quot;</span>: <span class="function"><span class="keyword">func</span><span class="params">(str <span class="type">string</span>)</span></span> template.HTML&#123;</span><br><span class="line">			<span class="keyword">return</span> template.HTML(str)</span><br><span class="line">		&#125;,</span><br><span class="line">	&#125;)</span><br><span class="line">	<span class="comment">//模板解析</span></span><br><span class="line">	r.LoadHTMLGlob(<span class="string">&quot;templates/**/*&quot;</span>)</span><br><span class="line">	<span class="comment">//模板渲染</span></span><br><span class="line">	r.GET(<span class="string">&quot;/posts&quot;</span>, <span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span> &#123;</span><br><span class="line">		c.HTML(http.StatusOK, <span class="string">&quot;posts/index.tmpl&quot;</span>, gin.H&#123;</span><br><span class="line">			<span class="string">&quot;title&quot;</span>: <span class="string">&quot;Posts index&quot;</span>,</span><br><span class="line">		&#125;)</span><br><span class="line">	&#125;)</span><br><span class="line">	r.GET(<span class="string">&quot;/users&quot;</span>, <span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span> &#123;</span><br><span class="line">		c.HTML(http.StatusOK, <span class="string">&quot;users/index.tmpl&quot;</span>, gin.H&#123;</span><br><span class="line">			<span class="string">&quot;title&quot;</span>: <span class="string">&quot;&lt;a href=&#x27;https://www.baidu.com&#x27;&gt;百度一下&lt;/a&gt;&quot;</span>,</span><br><span class="line">		&#125;)</span><br><span class="line">	&#125;)</span><br><span class="line">	r.Run(<span class="string">&quot;:9090&quot;</span>)</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>templates&#x2F;statics&#x2F;index.css内容</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">body &#123;</span><br><span class="line">    background-color: cadetblue;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>templates&#x2F;statics&#x2F;index.js内容</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">alert(<span class="number">123</span>);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>templates&#x2F;users&#x2F;index.tmpl内容</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">&#123;&#123;define <span class="string">&quot;users/index.tmpl&quot;</span>&#125;&#125;</span><br><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html lang=<span class="string">&quot;en&quot;</span>&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">    &lt;meta charset=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><br><span class="line">    &lt;link rel=<span class="string">&quot;stylesheet&quot;</span> href=<span class="string">&quot;/dwz/index.css&quot;</span>&gt;</span><br><span class="line">    &lt;title&gt;Title&lt;/title&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">&#123;&#123;.title | safe&#125;&#125;</span><br><span class="line">&lt;script src=<span class="string">&quot;/dwz/index.js&quot;</span>&gt;&lt;/script&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br><span class="line">&#123;&#123;end&#125;&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>运行程序：</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">go</span> run main.<span class="keyword">go</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>浏览器访问：</p>
<p>登录后复制  </p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">http:<span class="comment">//ip:9090/users</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="gin上传单文件"><a href="#gin上传单文件" class="headerlink" title="gin上传单文件"></a>gin上传单文件</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">&quot;X-UA-Compatible&quot;</span> <span class="attr">content</span>=<span class="string">&quot;IE=edge&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">&quot;viewport&quot;</span> <span class="attr">content</span>=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>Document<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">h2</span>&gt;</span>演示文件上传<span class="tag">&lt;/<span class="name">h2</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">form</span> <span class="attr">action</span>=<span class="string">&quot;/upload&quot;</span> <span class="attr">method</span>=<span class="string">&quot;post&quot;</span> <span class="attr">enctype</span>=<span class="string">&quot;multipart/form-data&quot;</span>&gt;</span></span><br><span class="line">        用户名：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">name</span>=<span class="string">&quot;username&quot;</span> <span class="attr">placeholder</span>=<span class="string">&quot;用户名&quot;</span> /&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">br</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">        头像：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;file&quot;</span> <span class="attr">name</span>=<span class="string">&quot;face&quot;</span> /&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">br</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;submit&quot;</span> <span class="attr">value</span>=<span class="string">&quot;提交&quot;</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">form</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">	<span class="string">&quot;fmt&quot;</span></span><br><span class="line">	<span class="string">&quot;log&quot;</span></span><br><span class="line"></span><br><span class="line">	<span class="string">&quot;github.com/gin-gonic/gin&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">	r := gin.Default()</span><br><span class="line">	r.LoadHTMLGlob(<span class="string">&quot;templates/*&quot;</span>)</span><br><span class="line"></span><br><span class="line">	<span class="comment">//上传操作页</span></span><br><span class="line">	<span class="comment">//设置内存限制（默认是32M），这里设置为8M</span></span><br><span class="line">	r.MaxMultipartMemory = <span class="number">8</span> &lt;&lt; <span class="number">20</span> <span class="comment">//8M</span></span><br><span class="line">	fmt.Println(r.MaxMultipartMemory)</span><br><span class="line">	r.POST(<span class="string">&quot;/upload&quot;</span>, <span class="function"><span class="keyword">func</span><span class="params">(c *gin.Context)</span></span> &#123;</span><br><span class="line">		file, err := c.FormFile(<span class="string">&quot;face&quot;</span>)</span><br><span class="line">		<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">			fmt.Println(<span class="string">&quot;读取表单失败&quot;</span>)</span><br><span class="line">			<span class="keyword">return</span></span><br><span class="line">		&#125;</span><br><span class="line">		log.Println(file.Filename)</span><br><span class="line">		path := <span class="string">`D:\go_ftp_dir`</span></span><br><span class="line">		pathFile := path + <span class="string">&quot;/&quot;</span> + file.Filename</span><br><span class="line">		c.SaveUploadedFile(file, pathFile)</span><br><span class="line">		c.String(<span class="number">200</span>, fmt.Sprintf(<span class="string">&quot;&#x27;%s&#x27; uploaded!&quot;</span>, file.Filename))</span><br><span class="line">	&#125;)</span><br><span class="line"></span><br><span class="line">	<span class="comment">//上传接口页</span></span><br><span class="line">	r.GET(<span class="string">&quot;/upload&quot;</span>, <span class="function"><span class="keyword">func</span><span class="params">(ctx *gin.Context)</span></span> &#123;</span><br><span class="line">		ctx.HTML(<span class="number">200</span>, <span class="string">&quot;upload.html&quot;</span>, gin.H&#123;&#125;)</span><br><span class="line">	&#125;)</span><br><span class="line"></span><br><span class="line">	r.Run(<span class="string">&quot;:8080&quot;</span>)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="crul-命令-也可以发送POST请求"><a href="#crul-命令-也可以发送POST请求" class="headerlink" title="crul 命令 也可以发送POST请求"></a>crul 命令 也可以发送POST请求</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">curl -X POST http://localhost:8080/upload \</span><br><span class="line">  -F &quot;file=@/tmp/aaa.zip&quot; \</span><br><span class="line">  -H &quot;Content-Type: multipart/form-data&quot;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="gin上传和下载"><a href="#gin上传和下载" class="headerlink" title="gin上传和下载"></a>gin上传和下载</h3><p>​	批量上传</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">httpRouter.POST(<span class="string">&quot;/upload&quot;</span>, <span class="function"><span class="keyword">func</span><span class="params">(ctx *gin.Context)</span></span> &#123;</span><br><span class="line">		forms, err := ctx.MultipartForm()</span><br><span class="line">		<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">			fmt.Println(<span class="string">&quot;error&quot;</span>, err)</span><br><span class="line">		&#125;</span><br><span class="line">		files := forms.File[<span class="string">&quot;fileName&quot;</span>]</span><br><span class="line">		<span class="keyword">for</span> _, v := <span class="keyword">range</span> files &#123;</span><br><span class="line">			<span class="keyword">if</span> err := ctx.SaveUploadedFile(v, fmt.Sprintf(<span class="string">&quot;%s%s&quot;</span>, <span class="string">&quot;./file/&quot;</span>, v.Filename)); err != <span class="literal">nil</span> &#123;</span><br><span class="line">				fmt.Println(<span class="string">&quot;保存文件失败&quot;</span>)</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>​	其实下载文件，通过http的get请求就行了，回去ctx.file()。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">httpRouter.GET(&quot;/download&quot;, func(ctx *gin.Context) &#123;</span><br><span class="line">		filePath := ctx.Query(&quot;url&quot;)</span><br><span class="line">		//打开文件</span><br><span class="line">		file, err := os.Open(&quot;./&quot; + filePath)</span><br><span class="line">		if err != nil &#123;</span><br><span class="line">			fmt.Println(&quot;打开文件错误&quot;, err)</span><br><span class="line">		&#125;</span><br><span class="line">		defer file.Close()</span><br><span class="line"></span><br><span class="line">		//获取文件的名称</span><br><span class="line">		fileName := path.Base(filePath)</span><br><span class="line">		ctx.Header(&quot;Content-Type&quot;, &quot;application/octet-stream&quot;)</span><br><span class="line">		ctx.Header(&quot;Content-Disposition&quot;, &quot;attachment; url=&quot;+fileName)</span><br><span class="line">		ctx.Header(&quot;Content-Transfer-Encoding&quot;, &quot;binary&quot;)</span><br><span class="line">		ctx.Header(&quot;Cache-Control&quot;, &quot;no-cache&quot;)</span><br><span class="line"></span><br><span class="line">		ctx.File(&quot;./&quot; + filePath)</span><br><span class="line">	&#125;)</span><br><span class="line"></span><br></pre></td></tr></table></figure>





<h2 id="自恢复集群启动命令oninitdb的设计与实现-之golang知识点"><a href="#自恢复集群启动命令oninitdb的设计与实现-之golang知识点" class="headerlink" title="自恢复集群启动命令oninitdb的设计与实现 之golang知识点"></a>自恢复集群启动命令oninitdb的设计与实现 之golang知识点</h2><h3 id="go执行os系统命令"><a href="#go执行os系统命令" class="headerlink" title="go执行os系统命令"></a>go执行os系统命令</h3><p>参考网站： <a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/296409942">https://zhuanlan.zhihu.com/p/296409942</a></p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">    <span class="string">&quot;bytes&quot;</span></span><br><span class="line">    <span class="string">&quot;fmt&quot;</span></span><br><span class="line">    <span class="string">&quot;log&quot;</span></span><br><span class="line">    <span class="string">&quot;os/exec&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">    cmd := exec.Command(<span class="string">&quot;ls&quot;</span>, <span class="string">&quot;-l&quot;</span>, <span class="string">&quot;/var/log/*.log&quot;</span>)</span><br><span class="line">    <span class="keyword">var</span> stdout, stderr bytes.Buffer</span><br><span class="line">    cmd.Stdout = &amp;stdout  <span class="comment">// 标准输出</span></span><br><span class="line">    cmd.Stderr = &amp;stderr  <span class="comment">// 标准错误</span></span><br><span class="line">    err := cmd.Run()</span><br><span class="line">    outStr, errStr := stdout.String(), stderr.String()</span><br><span class="line">    fmt.Printf(<span class="string">&quot;out:\n%s\nerr:\n%s\n&quot;</span>, outStr, errStr)</span><br><span class="line">    <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">        log.Fatalf(<span class="string">&quot;cmd.Run() failed with %s\n&quot;</span>, err)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="go发送get请求并解析网页的BodyString数据"><a href="#go发送get请求并解析网页的BodyString数据" class="headerlink" title="go发送get请求并解析网页的BodyString数据"></a>go发送get请求并解析网页的BodyString数据</h3><p>参考网站：<a target="_blank" rel="noopener" href="https://cloud.tencent.com/developer/article/1849807">https://cloud.tencent.com/developer/article/1849807</a></p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="comment">//主addrss</span></span><br><span class="line">	fmt.Println(<span class="string">&quot;远程添加&quot;</span>)</span><br><span class="line">	u := <span class="string">&quot;http://&quot;</span> + zhuip + <span class="string">&quot;:&quot;</span> + zhuport + <span class="string">&quot;/addrss?my=&quot;</span> + my</span><br><span class="line">	fmt.Println(u)</span><br><span class="line">	response, err := http.Get(u)</span><br><span class="line">	<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">		fmt.Println(<span class="string">&quot;http.Get addrss 时遇到异常&quot;</span>)</span><br><span class="line">	&#125;</span><br><span class="line">	buf, _ := ioutil.ReadAll(response.Body)</span><br><span class="line">	s := <span class="type">string</span>(buf)</span><br><span class="line">	<span class="keyword">if</span> s == <span class="string">&quot;run addrss ok&quot;</span> &#123;</span><br><span class="line">		fmt.Println(<span class="string">&quot;run addrss ok&quot;</span>)</span><br><span class="line">	&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">		fmt.Println(<span class="string">&quot;run addrss err&quot;</span>)</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="go返送get请求并解析网页BodyJSON数据到结构体"><a href="#go返送get请求并解析网页BodyJSON数据到结构体" class="headerlink" title="go返送get请求并解析网页BodyJSON数据到结构体"></a>go返送get请求并解析网页BodyJSON数据到结构体</h3><p>知识点：</p>
<ol>
<li>ioutil.ReadAll(response.Body) 读取所有Body数据</li>
<li>json.Unmarshal(buf, &amp;infoList[i]) 使用一个结构体地址解析json字符串</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">type Info struct &#123;</span><br><span class="line">	Servername string `JSON:&quot;servername&quot;`</span><br><span class="line">	Mode       string `JSON:&quot;mode&quot;`</span><br><span class="line">	Running    string `JSON:&quot;running&quot;`</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">var infoList [3]Info</span><br><span class="line"></span><br><span class="line">func info() &#123;</span><br><span class="line">	//查看db节点infof</span><br><span class="line">	fmt.Println(&quot;查看集群&quot;)</span><br><span class="line">	for i, n := range webList &#123;</span><br><span class="line">		response, err := http.Get(&quot;http://&quot; + n.ip + &quot;:&quot; + n.port + &quot;/info&quot;)</span><br><span class="line">		if err != nil &#123;</span><br><span class="line">			fmt.Println(&quot;info API 未正常提供服务，Docker可能已经异常。&quot;)</span><br><span class="line">			continue</span><br><span class="line">		&#125;</span><br><span class="line">		buf, _ := ioutil.ReadAll(response.Body)</span><br><span class="line">		json.Unmarshal(buf, &amp;infoList[i])</span><br><span class="line">		fmt.Println(infoList[i])</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="golang使用sftp和ssh"><a href="#golang使用sftp和ssh" class="headerlink" title="golang使用sftp和ssh"></a>golang使用sftp和ssh</h2><p>参考网站： <a target="_blank" rel="noopener" href="https://www.programminghunter.com/article/35971402517/">https://www.programminghunter.com/article/35971402517/</a></p>
<h3 id="sftp-go"><a href="#sftp-go" class="headerlink" title="sftp.go"></a>sftp.go</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br></pre></td><td class="code"><pre><span class="line">package sshclient</span><br><span class="line"></span><br><span class="line">import (</span><br><span class="line">	&quot;fmt&quot;</span><br><span class="line">	&quot;log&quot;</span><br><span class="line">	&quot;net&quot;</span><br><span class="line">	&quot;os&quot;</span><br><span class="line">	&quot;path&quot;</span><br><span class="line">	&quot;time&quot;</span><br><span class="line"></span><br><span class="line">	&quot;github.com/pkg/sftp&quot;</span><br><span class="line">	&quot;golang.org/x/crypto/ssh&quot;</span><br><span class="line">)</span><br><span class="line"></span><br><span class="line">func connect(user, password, host string, port int) (*sftp.Client, error) &#123;</span><br><span class="line">	var (</span><br><span class="line">		auth         []ssh.AuthMethod</span><br><span class="line">		addr         string</span><br><span class="line">		clientConfig *ssh.ClientConfig</span><br><span class="line">		sshClient    *ssh.Client</span><br><span class="line">		sftpClient   *sftp.Client</span><br><span class="line">		err          error</span><br><span class="line">	)</span><br><span class="line">	// get auth method</span><br><span class="line">	auth = make([]ssh.AuthMethod, 0)</span><br><span class="line">	auth = append(auth, ssh.Password(password))</span><br><span class="line">	hostKeyCallbk := func(hostname string, remote net.Addr, key ssh.PublicKey) error &#123;</span><br><span class="line">		return nil</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	clientConfig = &amp;ssh.ClientConfig&#123;</span><br><span class="line">		User:            user,</span><br><span class="line">		Auth:            auth,</span><br><span class="line">		Timeout:         1 * time.Second,</span><br><span class="line">		HostKeyCallback: hostKeyCallbk,</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	// connet to ssh</span><br><span class="line">	addr = fmt.Sprintf(&quot;%s:%d&quot;, host, port)</span><br><span class="line"></span><br><span class="line">	if sshClient, err = ssh.Dial(&quot;tcp&quot;, addr, clientConfig); err != nil &#123;</span><br><span class="line">		return nil, err</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	// create sftp client</span><br><span class="line">	if sftpClient, err = sftp.NewClient(sshClient); err != nil &#123;</span><br><span class="line">		return nil, err</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	return sftpClient, nil</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">//发送文件</span><br><span class="line">func SftpPut(user, password, host, fileName string) &#123;</span><br><span class="line">	var (</span><br><span class="line">		err        error</span><br><span class="line">		sftpClient *sftp.Client</span><br><span class="line">	)</span><br><span class="line"></span><br><span class="line">	// 这里换成实际的 SSH 连接的 用户名，密码，主机名或IP，SSH端口</span><br><span class="line">	sftpClient, err = connect(user, password, host, 22)</span><br><span class="line">	if err != nil &#123;</span><br><span class="line">		log.Fatal(err)</span><br><span class="line">	&#125;</span><br><span class="line">	defer sftpClient.Close()</span><br><span class="line"></span><br><span class="line">	// 用来测试的本地文件路径 和 远程机器上的文件夹</span><br><span class="line">	var localFilePath = fileName</span><br><span class="line">	var remoteDir = &quot;/tmp/&quot;</span><br><span class="line">	srcFile, err := os.Open(localFilePath)</span><br><span class="line">	if err != nil &#123;</span><br><span class="line">		log.Fatal(err)</span><br><span class="line">	&#125;</span><br><span class="line">	defer srcFile.Close()</span><br><span class="line"></span><br><span class="line">	var remoteFileName = path.Base(localFilePath)</span><br><span class="line">	dstFile, err := sftpClient.Create(path.Join(remoteDir, remoteFileName))</span><br><span class="line">	if err != nil &#123;</span><br><span class="line">		log.Fatal(err)</span><br><span class="line">	&#125;</span><br><span class="line">	defer dstFile.Close()</span><br><span class="line"></span><br><span class="line">	buf := make([]byte, 1024)</span><br><span class="line">	for &#123;</span><br><span class="line">		n, _ := srcFile.Read(buf)</span><br><span class="line">		if n == 0 &#123;</span><br><span class="line">			break</span><br><span class="line">		&#125;</span><br><span class="line">		dstFile.Write(buf[:n])</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	fmt.Println(&quot;copy file to remote server finished!&quot;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">//下载文件</span><br><span class="line">func SftpGet(user, password, host, fileName string) &#123;</span><br><span class="line"></span><br><span class="line">	var (</span><br><span class="line">		err        error</span><br><span class="line">		sftpClient *sftp.Client</span><br><span class="line">	)</span><br><span class="line"></span><br><span class="line">	// 这里换成实际的 SSH 连接的 用户名，密码，主机名或IP，SSH端口</span><br><span class="line">	sftpClient, err = connect(user, password, host, 22)</span><br><span class="line">	if err != nil &#123;</span><br><span class="line">		log.Fatal(err)</span><br><span class="line">	&#125;</span><br><span class="line">	defer sftpClient.Close()</span><br><span class="line"></span><br><span class="line">	// 用来测试的远程文件路径 和 本地文件夹</span><br><span class="line">	var remoteFilePath = &quot;/tmp/&quot; + fileName</span><br><span class="line">	var localDir = &quot;lib/sshclient/sftpput/&quot;</span><br><span class="line"></span><br><span class="line">	srcFile, err := sftpClient.Open(remoteFilePath)</span><br><span class="line">	if err != nil &#123;</span><br><span class="line">		log.Fatal(err)</span><br><span class="line">	&#125;</span><br><span class="line">	defer srcFile.Close()</span><br><span class="line"></span><br><span class="line">	var localFileName = path.Base(remoteFilePath)</span><br><span class="line">	dstFile, err := os.Create(path.Join(localDir, localFileName))</span><br><span class="line">	if err != nil &#123;</span><br><span class="line">		log.Fatal(err)</span><br><span class="line">	&#125;</span><br><span class="line">	defer dstFile.Close()</span><br><span class="line"></span><br><span class="line">	if _, err = srcFile.WriteTo(dstFile); err != nil &#123;</span><br><span class="line">		log.Fatal(err)</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	fmt.Println(&quot;copy file from remote server finished!&quot;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="sshclient-go"><a href="#sshclient-go" class="headerlink" title="sshclient.go"></a>sshclient.go</h3><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> sshclient</span><br><span class="line"></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">go 1.14:</span></span><br><span class="line"><span class="comment">mkdir -p $GOPATH/src/golang.org/x/</span></span><br><span class="line"><span class="comment">cd $GOPATH/src/golang.org/x/</span></span><br><span class="line"><span class="comment">git clone https://github.com/golang/crypto.git</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">go 1.18</span></span><br><span class="line"><span class="comment">go get golang.org/x/crypto/ssh</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">	<span class="string">&quot;bytes&quot;</span></span><br><span class="line">	<span class="string">&quot;fmt&quot;</span></span><br><span class="line">	<span class="string">&quot;net&quot;</span></span><br><span class="line">	<span class="string">&quot;strings&quot;</span></span><br><span class="line">	<span class="string">&quot;time&quot;</span></span><br><span class="line"></span><br><span class="line">	<span class="string">&quot;golang.org/x/crypto/ssh&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="comment">// SSHConnect ssh连接</span></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">SSHConnect</span><span class="params">(user, password, host <span class="type">string</span>, port <span class="type">int</span>)</span></span> (*ssh.Client, *ssh.Session, <span class="type">error</span>) &#123;</span><br><span class="line">	<span class="keyword">var</span> (</span><br><span class="line">		auth         []ssh.AuthMethod</span><br><span class="line">		addr         <span class="type">string</span></span><br><span class="line">		clientConfig *ssh.ClientConfig</span><br><span class="line">		client       *ssh.Client</span><br><span class="line">		session      *ssh.Session</span><br><span class="line">		err          <span class="type">error</span></span><br><span class="line">	)</span><br><span class="line">	<span class="comment">// get auth method</span></span><br><span class="line">	auth = <span class="built_in">make</span>([]ssh.AuthMethod, <span class="number">0</span>)</span><br><span class="line">	auth = <span class="built_in">append</span>(auth, ssh.Password(password))</span><br><span class="line"></span><br><span class="line">	hostKeyCallbk := <span class="function"><span class="keyword">func</span><span class="params">(hostname <span class="type">string</span>, remote net.Addr, key ssh.PublicKey)</span></span> <span class="type">error</span> &#123;</span><br><span class="line">		<span class="keyword">return</span> <span class="literal">nil</span></span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	clientConfig = &amp;ssh.ClientConfig&#123;</span><br><span class="line">		User:            user,</span><br><span class="line">		Auth:            auth,</span><br><span class="line">		Timeout:         <span class="number">1</span> * time.Second,</span><br><span class="line">		HostKeyCallback: hostKeyCallbk,</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="comment">// connet to ssh</span></span><br><span class="line">	addr = fmt.Sprintf(<span class="string">&quot;%s:%d&quot;</span>, host, port)</span><br><span class="line"></span><br><span class="line">	<span class="keyword">if</span> client, err = ssh.Dial(<span class="string">&quot;tcp&quot;</span>, addr, clientConfig); err != <span class="literal">nil</span> &#123;</span><br><span class="line">		<span class="keyword">return</span> <span class="literal">nil</span>, <span class="literal">nil</span>, err</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="comment">// create session</span></span><br><span class="line">	<span class="keyword">if</span> session, err = client.NewSession(); err != <span class="literal">nil</span> &#123;</span><br><span class="line">		<span class="keyword">return</span> client, <span class="literal">nil</span>, err</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">return</span> client, session, <span class="literal">nil</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// RunSSHpiliang 执行ssh 批量登陆执行</span></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">RunSSHpiliang</span><span class="params">(user, password, host, cmdshell <span class="type">string</span>)</span></span> <span class="type">string</span> &#123;</span><br><span class="line">	<span class="keyword">var</span> stdOut, stdErr bytes.Buffer</span><br><span class="line">	client, session, err := SSHConnect(user, password, host, <span class="number">22</span>)</span><br><span class="line">	<span class="keyword">if</span> client != <span class="literal">nil</span> &#123;</span><br><span class="line">		<span class="keyword">defer</span> client.Close()</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">if</span> session != <span class="literal">nil</span> &#123;</span><br><span class="line">		<span class="keyword">defer</span> session.Close()</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">		<span class="comment">//fmt.Println(err,&quot;   wei----------------------------------------&quot;)</span></span><br><span class="line">		<span class="keyword">if</span> strings.Contains(err.Error(), <span class="string">&quot;i/o timeout&quot;</span>) &#123;</span><br><span class="line">			<span class="keyword">return</span> <span class="string">&quot;连接主机的22端口时出错&quot;</span></span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span> strings.Contains(err.Error(), <span class="string">&quot;unable to authenticate&quot;</span>) &#123;</span><br><span class="line">			<span class="keyword">return</span> <span class="string">&quot;密码或SSHKEY验证时出错&quot;</span></span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">return</span> <span class="string">&quot;登录主机时出错&quot;</span></span><br><span class="line">	&#125;</span><br><span class="line">	session.Stdout = &amp;stdOut</span><br><span class="line">	session.Stderr = &amp;stdErr</span><br><span class="line">	<span class="keyword">if</span> err := session.Run(cmdshell); err != <span class="literal">nil</span> &#123;</span><br><span class="line">		<span class="comment">// fmt.Println(err.Error())</span></span><br><span class="line">		<span class="comment">// fmt.Println(stdOut.String())</span></span><br><span class="line">		<span class="keyword">return</span> <span class="string">&quot;执行命令时出错！&quot;</span></span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> stdOut.String()</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="golang-文件IO-x2F-目录IO-x2F-行IO-x2F-字节BUFIO"><a href="#golang-文件IO-x2F-目录IO-x2F-行IO-x2F-字节BUFIO" class="headerlink" title="golang 文件IO&#x2F;目录IO&#x2F;行IO&#x2F;字节BUFIO"></a>golang 文件IO&#x2F;目录IO&#x2F;行IO&#x2F;字节BUFIO</h2><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">	<span class="string">&quot;bufio&quot;</span></span><br><span class="line">	<span class="string">&quot;fmt&quot;</span></span><br><span class="line">	<span class="string">&quot;io&quot;</span></span><br><span class="line">	<span class="string">&quot;os&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">weiShuoMing</span><span class="params">()</span></span> &#123;</span><br><span class="line">	<span class="comment">// 删除覆盖   os.OpenFile(&quot;aaa&quot;, os.O_CREATE|os.O_RDWR, 6)</span></span><br><span class="line">	<span class="comment">// 行写文件   os.Openfile(&quot;aaa&quot;, os.O_CREATE|os.O_RDWD|os.O_APPEND,6)   f.WriteString(&quot;&quot;)</span></span><br><span class="line"></span><br><span class="line">	<span class="comment">// reader定义 reader,err := bufio.Reader(f)</span></span><br><span class="line">	<span class="comment">// 行读文件   os.Openfile(&quot;aaa&quot;,io.O_RDONLY,6) 或者用 os.Open(&quot;aaa&quot;)  f.ReadBytes(&#x27;\n&#x27;)</span></span><br><span class="line">	<span class="comment">// 偏移量     io.Seek(-12,io.SeekBeging) 还有Current和End</span></span><br><span class="line"></span><br><span class="line">	<span class="comment">// buf大小	 buf := make([]byte,4096)</span></span><br><span class="line">	<span class="comment">// 字节写文件  n,err:=reader.write(buf)</span></span><br><span class="line">	<span class="comment">// 字节读文件  n,err:=reader.read(buf)</span></span><br><span class="line"></span><br><span class="line">	<span class="comment">// 打开目录    os.Openfile(&quot;aaa&quot;,io.O_RDONLY,os.ModeDir)</span></span><br><span class="line">	<span class="comment">// 读取目录项   f.Readdir(-1) 返回[&#123;Size() Name() IsDir() Modetime()&#125;...]</span></span><br><span class="line"></span><br><span class="line">	<span class="comment">// https://studygolang.com/pkgdoc</span></span><br><span class="line">	<span class="comment">// https://www.bilibili.com/video/BV1TK4y1a7ex?from=search&amp;seid=18159148304738299137</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">	<span class="comment">// 创建覆盖文件</span></span><br><span class="line">	os.Create(<span class="string">&quot;aaa&quot;</span>)</span><br><span class="line">	<span class="comment">// 打开文件aaa</span></span><br><span class="line">	f, err := os.OpenFile(<span class="string">&quot;aaa&quot;</span>, os.O_RDWR|os.O_APPEND, <span class="number">6</span>)</span><br><span class="line">	<span class="keyword">if</span> err != <span class="literal">nil</span> &amp;&amp; err != io.EOF &#123;</span><br><span class="line">		fmt.Println(<span class="string">&quot;OpenFile打开文件aaa出错&quot;</span>)</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">defer</span> f.Close()</span><br><span class="line">	<span class="comment">// 写入5行数据</span></span><br><span class="line">	f.WriteString(<span class="string">&quot;写入数据0001\n&quot;</span>)</span><br><span class="line">	f.WriteString(<span class="string">&quot;写入数据0002\n写入数据0003\n&quot;</span>)</span><br><span class="line">	f.WriteString(<span class="string">&quot;写入数据0004\n写入数据0005\n&quot;</span>)</span><br><span class="line">	<span class="comment">// 移至文件开头</span></span><br><span class="line">	f.Seek(<span class="number">0</span>, io.SeekStart)</span><br><span class="line">	<span class="comment">// 读取第2,3行的数据</span></span><br><span class="line">	reader := bufio.NewReader(f)</span><br><span class="line">	i := <span class="number">0</span></span><br><span class="line">	<span class="keyword">for</span> &#123;</span><br><span class="line">		hang, err := reader.ReadBytes(<span class="string">&#x27;\n&#x27;</span>)</span><br><span class="line">		<span class="keyword">if</span> err == io.EOF &#123;</span><br><span class="line">			<span class="keyword">break</span></span><br><span class="line">		&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">			i++</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span> i == <span class="number">2</span> || i == <span class="number">3</span> &#123;</span><br><span class="line">			fmt.Print(<span class="type">string</span>(hang))</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="comment">// buf读</span></span><br><span class="line">	<span class="comment">// 偏移15字节再读取第12,13,14,15,16,17,18,19个字节 (utf8一个汉字3个字节,换行\n为一个字节)</span></span><br><span class="line">	f.Seek(<span class="number">15</span>, io.SeekStart)</span><br><span class="line">	buf := <span class="built_in">make</span>([]<span class="type">byte</span>, <span class="number">8</span>)</span><br><span class="line">	f.Read(buf) <span class="comment">//从f中读取一个buf空间的内容，给buf赋值。这个函数还返回n,err其中n是实际读取的切片长度。</span></span><br><span class="line">	fmt.Printf(<span class="string">&quot;%q\n&quot;</span>, buf)</span><br><span class="line">	<span class="comment">// buf写</span></span><br><span class="line">	f.Seek(<span class="number">0</span>, io.SeekEnd)</span><br><span class="line">	f.Write(buf)</span><br><span class="line">	f.Close()</span><br><span class="line"></span><br><span class="line">	<span class="comment">// 读取文件夹</span></span><br><span class="line">	fd, err := os.OpenFile(<span class="string">&quot;D:/w_gopath/src/wei01/w_go_pg_tidb/05.go_wei&quot;</span>, os.O_RDONLY, os.ModeDir)</span><br><span class="line">	<span class="keyword">defer</span> fd.Close()</span><br><span class="line">	fdreader, err := fd.Readdir(<span class="number">-1</span>)</span><br><span class="line">	<span class="keyword">for</span> zixiang, info := <span class="keyword">range</span> fdreader &#123;</span><br><span class="line">		fmt.Println(zixiang, info.Name(), info.Size(), info.ModTime(), info.IsDir())</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 大文件复制</span></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">weicopy</span><span class="params">()</span></span> &#123;</span><br><span class="line">	f4, err := os.Open(<span class="string">&quot;wei.mp3&quot;</span>)</span><br><span class="line">	<span class="keyword">if</span> err != <span class="literal">nil</span> &amp;&amp; err != io.EOF &#123;</span><br><span class="line">		fmt.Println(<span class="string">&quot;打开mp3失败&quot;</span>)</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">defer</span> f4.Close()</span><br><span class="line"></span><br><span class="line">	f5, err := os.Create(<span class="string">&quot;wei_2.mp3&quot;</span>)</span><br><span class="line">	<span class="keyword">if</span> err != <span class="literal">nil</span> &amp;&amp; err != io.EOF &#123;</span><br><span class="line">		fmt.Println(<span class="string">&quot;打开mp3失败&quot;</span>)</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">defer</span> f5.Close()</span><br><span class="line"></span><br><span class="line">	buf4k := <span class="built_in">make</span>([]<span class="type">byte</span>, <span class="number">4096</span>)</span><br><span class="line">	<span class="keyword">for</span> &#123;</span><br><span class="line">		n, err := f4.Read(buf4k)</span><br><span class="line">		f5.Write(buf4k[:n])</span><br><span class="line">		<span class="keyword">if</span> err != <span class="literal">nil</span> &amp;&amp; err != io.EOF &#123;</span><br><span class="line">			fmt.Println(<span class="string">&quot;读取文件出错&quot;</span>)</span><br><span class="line">			<span class="keyword">break</span></span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span> n == <span class="number">0</span> &#123;</span><br><span class="line">			fmt.Println(<span class="string">&quot;文件全部读完了&quot;</span>)</span><br><span class="line">			<span class="keyword">break</span></span><br><span class="line">		&#125;</span><br><span class="line">		fmt.Println(n)</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p> JSON（<a target="_blank" rel="noopener" href="http://c.biancheng.net/js/">JavaScript</a> Object Notation）是一种轻量级的数据交换格式，易于阅读和编写，同时也易于机器解析和生成。它基于 <a target="_blank" rel="noopener" href="http://c.biancheng.net/java/">Java</a>Script Programming Language, Standard ECMA-262 3rd Edition - December 1999 的一个子集。</p>
<p> JSON 是一种使用 UTF-8 编码的纯文本格式，采用完全独立于语言的文本格式，由于写起来比 XML 格式方便，并且更为紧凑，同时所需的处理时间也更少，致使 JSON 格式越来越流行，特别是在通过网络连接传送数据方面。</p>
<p> 开发人员可以使用 JSON 传输简单的字符串、数字、布尔值，也可以传输一个数组或者一个更复杂的复合结构。在 Web 开发领域中，JSON 被广泛应用于 Web 服务端程序和客户端之间的数据通信。</p>
<p> Go语言内建对 JSON 的支持，使用内置的 encoding&#x2F;json 标准库，开发人员可以轻松使用Go程序生成和解析 JSON 格式的数据。</p>
<p> JSON 结构如下所示： </p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span><span class="attr">&quot;key1&quot;</span><span class="punctuation">:</span><span class="string">&quot;value1&quot;</span><span class="punctuation">,</span><span class="attr">&quot;key2&quot;</span><span class="punctuation">:</span>value2<span class="punctuation">,</span><span class="attr">&quot;key3&quot;</span><span class="punctuation">:</span><span class="punctuation">[</span><span class="string">&quot;value3&quot;</span><span class="punctuation">,</span><span class="string">&quot;value4&quot;</span><span class="punctuation">,</span><span class="string">&quot;value5&quot;</span><span class="punctuation">]</span><span class="punctuation">&#125;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="写-JSON-文件"><a href="#写-JSON-文件" class="headerlink" title="写 JSON 文件"></a>写 JSON 文件</h2><p> 使用Go语言创建一个 json 文件非常方便，示例代码如下： </p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">    <span class="string">&quot;encoding/json&quot;</span></span><br><span class="line">    <span class="string">&quot;fmt&quot;</span></span><br><span class="line">    <span class="string">&quot;os&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="keyword">type</span> Website <span class="keyword">struct</span> &#123;</span><br><span class="line">    Name   <span class="type">string</span> <span class="string">`xml:&quot;name,attr&quot;`</span></span><br><span class="line">    Url    <span class="type">string</span></span><br><span class="line">    Course []<span class="type">string</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">    info := []Website&#123;&#123;<span class="string">&quot;Golang&quot;</span>, <span class="string">&quot;http://c.biancheng.net/golang/&quot;</span>, []<span class="type">string</span>&#123;<span class="string">&quot;http://c.biancheng.net/cplus/&quot;</span>, <span class="string">&quot;http://c.biancheng.net/linux_tutorial/&quot;</span>&#125;&#125;, &#123;<span class="string">&quot;Java&quot;</span>, <span class="string">&quot;http://c.biancheng.net/java/&quot;</span>, []<span class="type">string</span>&#123;<span class="string">&quot;http://c.biancheng.net/socket/&quot;</span>, <span class="string">&quot;http://c.biancheng.net/python/&quot;</span>&#125;&#125;&#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 创建文件</span></span><br><span class="line">    filePtr, err := os.Create(<span class="string">&quot;info.json&quot;</span>)</span><br><span class="line">    <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">        fmt.Println(<span class="string">&quot;文件创建失败&quot;</span>, err.Error())</span><br><span class="line">        <span class="keyword">return</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">defer</span> filePtr.Close()</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 创建Json编码器</span></span><br><span class="line">    encoder := json.NewEncoder(filePtr)</span><br><span class="line"></span><br><span class="line">    err = encoder.Encode(info)</span><br><span class="line">    <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">        fmt.Println(<span class="string">&quot;编码错误&quot;</span>, err.Error())</span><br><span class="line"></span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        fmt.Println(<span class="string">&quot;编码成功&quot;</span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p> 运行上面的代码会在当前目录下生成一个 info.json 文件，文件内容如下：  </p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">[</span></span><br><span class="line">    <span class="punctuation">&#123;</span></span><br><span class="line">        <span class="attr">&quot;Name&quot;</span><span class="punctuation">:</span><span class="string">&quot;Golang&quot;</span><span class="punctuation">,</span></span><br><span class="line">        <span class="attr">&quot;Url&quot;</span><span class="punctuation">:</span><span class="string">&quot;http://c.biancheng.net/golang/&quot;</span><span class="punctuation">,</span></span><br><span class="line">        <span class="attr">&quot;Course&quot;</span><span class="punctuation">:</span><span class="punctuation">[</span></span><br><span class="line">            <span class="string">&quot;http://c.biancheng.net/golang/102/&quot;</span><span class="punctuation">,</span></span><br><span class="line">            <span class="string">&quot;http://c.biancheng.net/golang/concurrent/&quot;</span></span><br><span class="line">        <span class="punctuation">]</span></span><br><span class="line">    <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="punctuation">&#123;</span></span><br><span class="line">        <span class="attr">&quot;Name&quot;</span><span class="punctuation">:</span><span class="string">&quot;Java&quot;</span><span class="punctuation">,</span></span><br><span class="line">        <span class="attr">&quot;Url&quot;</span><span class="punctuation">:</span><span class="string">&quot;http://c.biancheng.net/java/&quot;</span><span class="punctuation">,</span></span><br><span class="line">        <span class="attr">&quot;Course&quot;</span><span class="punctuation">:</span><span class="punctuation">[</span></span><br><span class="line">            <span class="string">&quot;http://c.biancheng.net/java/10/&quot;</span><span class="punctuation">,</span></span><br><span class="line">            <span class="string">&quot;http://c.biancheng.net/python/&quot;</span></span><br><span class="line">        <span class="punctuation">]</span></span><br><span class="line">    <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">]</span></span><br></pre></td></tr></table></figure>

<h2 id="读-JSON-文件"><a href="#读-JSON-文件" class="headerlink" title="读 JSON 文件"></a>读 JSON 文件</h2><p> 读 JSON 数据与写 JSON 数据一样简单，示例代码如下： </p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">    <span class="string">&quot;encoding/json&quot;</span></span><br><span class="line">    <span class="string">&quot;fmt&quot;</span></span><br><span class="line">    <span class="string">&quot;os&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="keyword">type</span> Website <span class="keyword">struct</span> &#123;</span><br><span class="line">    Name   <span class="type">string</span> <span class="string">`xml:&quot;name,attr&quot;`</span></span><br><span class="line">    Url    <span class="type">string</span></span><br><span class="line">    Course []<span class="type">string</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">    filePtr, err := os.Open(<span class="string">&quot;./info.json&quot;</span>)</span><br><span class="line">    <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">        fmt.Println(<span class="string">&quot;文件打开失败 [Err:%s]&quot;</span>, err.Error())</span><br><span class="line">        <span class="keyword">return</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">defer</span> filePtr.Close()</span><br><span class="line">    <span class="keyword">var</span> info []Website</span><br><span class="line">    <span class="comment">// 创建json解码器</span></span><br><span class="line">    decoder := json.NewDecoder(filePtr)</span><br><span class="line">    err = decoder.Decode(&amp;info)</span><br><span class="line">    <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">        fmt.Println(<span class="string">&quot;解码失败&quot;</span>, err.Error())</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        fmt.Println(<span class="string">&quot;解码成功&quot;</span>)</span><br><span class="line">        fmt.Println(info)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p> 运行结果如下： </p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">go run main.go</span><br><span class="line">解码成功</span><br><span class="line"><span class="punctuation">[</span><span class="punctuation">&#123;</span>Golang http<span class="punctuation">:</span><span class="comment">//c.biancheng.net/golang/ [http://c.biancheng.net/golang/102/ http://c.biancheng.net/golang/concurrent/]&#125; &#123;Java http://c.biancheng.net/java/ [http://c.biancheng.net/java/10/ http://c.biancheng.net/python/]&#125;]</span></span><br></pre></td></tr></table></figure>

<p>顺便提一下，还有一种叫做 BSON (Binary JSON) 的格式与 JSON 非常类似，与 JSON 相比，BSON 着眼于提高存储和扫描效率。BSON  文档中的大型元素以长度字段为前缀以便于扫描。在某些情况下，由于长度前缀和显式数组索引的存在，BSON 使用的空间会多于 JSON。</p>
<h1 id="Golang-操作mysql"><a href="#Golang-操作mysql" class="headerlink" title="Golang 操作mysql"></a>Golang 操作mysql</h1><figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">go get github.com/go<span class="literal">-sql-driver</span>/mysql</span><br><span class="line">go get github.com/jmoiron/sqlx</span><br></pre></td></tr></table></figure> 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%9F%BA%E7%A1%80/" rel="tag">基础</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
    <article
  id="post-入门-Vue之路"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/05/10/%E5%85%A5%E9%97%A8-Vue%E4%B9%8B%E8%B7%AF/"
    >入门-Vue之路</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/05/10/%E5%85%A5%E9%97%A8-Vue%E4%B9%8B%E8%B7%AF/" class="article-date">
  <time datetime="2023-05-10T00:58:06.000Z" itemprop="datePublished">2023-05-10</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/JavaScript/">JavaScript</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h2 id="官网"><a href="#官网" class="headerlink" title="官网"></a>官网</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">vue3：  https://cn.vuejs.org/</span><br><span class="line">vue2：  https://v2.cn.vuejs.org/v2/guide/</span><br><span class="line"></span><br><span class="line">#安装开发者工具 在我的网盘里面</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="下载Vue-js"><a href="#下载Vue-js" class="headerlink" title="下载Vue.js"></a>下载Vue.js</h2><p> 你也可以<a target="_blank" rel="noopener" href="https://github.com/vuejs/v2.vuejs.org/blob/master/src/v2/examples/vue-20-hello-world/index.html">创建一个 <code>.html</code> 文件</a>，然后通过如下方式引入 Vue： </p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- 开发环境版本，包含了有帮助的命令行警告 --&gt;</span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span></span><br><span class="line"></span><br><span class="line">或者这样：</span><br><span class="line">&lt;script type=<span class="string">&quot;text/javascript&quot;</span> src=<span class="string">&quot;../js/vue.js&quot;</span>&gt;&lt;/script&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- 生产环境版本，优化了尺寸和速度 --&gt;</span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;https://cdn.jsdelivr.net/npm/vue@2&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>说明： 这两个文件可以下载到本地。</p>
<h2 id="NPM方式创建项目"><a href="#NPM方式创建项目" class="headerlink" title="NPM方式创建项目"></a>NPM方式创建项目</h2><h3 id="安装Vue-CLI"><a href="#安装Vue-CLI" class="headerlink" title="安装Vue-CLI"></a>安装Vue-CLI</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">先安装 Node.js</span> </span><br><span class="line">npm 64 位安装包下载地址 : https://nodejs.org/dist/latest/node-v18.8.0-x64.msi</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">再安装 vue-cli</span></span><br><span class="line">npm install --global vue-cli</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="创建一个Vue项目"><a href="#创建一个Vue项目" class="headerlink" title="创建一个Vue项目"></a>创建一个Vue项目</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">创建一个基于webpack模板的新项目 (需要用cmd终端)</span></span><br><span class="line">vue init webpack my-blog</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">创建项目的过程</span></span><br><span class="line">? Project name my-blog</span><br><span class="line">? Project description A Vue.js project</span><br><span class="line">? Author wangwei</span><br><span class="line">? Vue build standalone</span><br><span class="line">? Install vue-router? Yes</span><br><span class="line">? Use ESLint to lint your code? No</span><br><span class="line">? Set up unit tests No</span><br><span class="line">? Setup e2e tests with Nightwatch? No</span><br><span class="line">? Should we run `npm install` for you after the project has been created? (recommended) npm           </span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">启动项目</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">Project initialization finished!</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">========================</span></span><br><span class="line">To get started:</span><br><span class="line">  cd my-blog</span><br><span class="line">  npm run dev</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="启动一个Vue项目"><a href="#启动一个Vue项目" class="headerlink" title="启动一个Vue项目"></a>启动一个Vue项目</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">cd D:\VSCodeSrc\src\Vue\my-blog</span><br><span class="line">npm install prettier@~1.12.0 -D</span><br><span class="line">npm install --save module vue-resource</span><br><span class="line">npm install qs --save</span><br><span class="line">npm install --save console</span><br><span class="line">npm install --save axiox</span><br><span class="line">npm install element-ui –save</span><br><span class="line">npm run dev</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>​	访问： <a target="_blank" rel="noopener" href="http://localhost:8080/">http://localhost:8080</a></p>
<h2 id="手工方式创建项目"><a href="#手工方式创建项目" class="headerlink" title="手工方式创建项目"></a>手工方式创建项目</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">创建项目目录</span></span><br><span class="line">cd D:\VSCodeSrc\src\Vue\wangweiVue\01_初识Vue</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">创建js目录</span></span><br><span class="line">cd D:\VSCodeSrc\src\Vue\wangweiVue\js</span><br><span class="line">	上传vue.js和vue.min.js</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h6 id="在项目目录下创建html，引用vue-jquery-关闭非生产版提示"><a href="#在项目目录下创建html，引用vue-jquery-关闭非生产版提示" class="headerlink" title="在项目目录下创建html，引用vue,jquery,关闭非生产版提示"></a>在项目目录下创建html，引用vue,jquery,关闭非生产版提示</h6><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">&quot;X-UA-Compatible&quot;</span> <span class="attr">content</span>=<span class="string">&quot;IE=edge&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">&quot;viewport&quot;</span> <span class="attr">content</span>=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>01_初识Vue<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">    </span><br><span class="line">    <span class="comment">&lt;!-- 引入vue --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span> <span class="attr">src</span>=<span class="string">&quot;../js/vue.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span> <span class="attr">src</span>=<span class="string">&quot;../js/jquery.min.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"><span class="title class_">Vue</span>.<span class="property">config</span>.<span class="property">productionTip</span>=<span class="literal">false</span></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;root&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">h1</span>&gt;</span>Hello, &#123;&#123;name&#125;&#125; &#123;&#123;school.url.toUpperCase()&#125;&#125; &#123;&#123;school.name&#125;&#125; &#123;&#123;Date.now()&#125;&#125;<span class="tag">&lt;/<span class="name">h1</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">a</span> <span class="attr">:href</span>=<span class="string">&quot;school.url&quot;</span>&gt;</span>点我去网站，指令语法绑定href<span class="tag">&lt;/<span class="name">a</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">        单向绑定：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span>  <span class="attr">v-bind:value</span>=<span class="string">&quot;name&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">        双向绑定：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">v-model:value</span>=<span class="string">&quot;name&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">        单向简写：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span>        <span class="attr">:value</span>=<span class="string">&quot;name&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">        双向简写：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">v-model</span>      =<span class="string">&quot;name&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">        <span class="comment">//创建Vue实例vm</span></span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">const</span> vm = <span class="keyword">new</span> <span class="title class_">Vue</span>(&#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="comment">//容器和元素element绑定</span></span></span><br><span class="line"><span class="language-javascript">            <span class="comment">// el:&#x27;#root&#x27;,</span></span></span><br><span class="line"><span class="language-javascript">            <span class="comment">//数据</span></span></span><br><span class="line"><span class="language-javascript">            <span class="attr">data</span>:&#123;</span></span><br><span class="line"><span class="language-javascript">                <span class="attr">name</span>:<span class="string">&#x27;汪伟&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">                <span class="attr">age</span>:<span class="number">36</span>,</span></span><br><span class="line"><span class="language-javascript">                <span class="attr">school</span>:&#123;</span></span><br><span class="line"><span class="language-javascript">                    <span class="attr">name</span>:<span class="string">&quot;天然小学&quot;</span>,</span></span><br><span class="line"><span class="language-javascript">                    <span class="attr">url</span>:<span class="string">&quot;http://www.baidu.com&quot;</span></span></span><br><span class="line"><span class="language-javascript">                &#125;</span></span><br><span class="line"><span class="language-javascript">            &#125;</span></span><br><span class="line"><span class="language-javascript">        &#125;)</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">        <span class="variable language_">console</span>.<span class="title function_">log</span>(vm)</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">        <span class="built_in">setTimeout</span>(<span class="function">()=&gt;</span>&#123;</span></span><br><span class="line"><span class="language-javascript">            vm.$mount(<span class="string">&quot;#root&quot;</span>)</span></span><br><span class="line"><span class="language-javascript">        &#125;,<span class="number">1000</span>)</span></span><br><span class="line"><span class="language-javascript">        </span></span><br><span class="line"><span class="language-javascript">    </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>​		说明： </p>
<p>​					<strong>id和#配对， class和.配对。一个是id选择器，一个是类选择器。</strong></p>
<p>​					<strong>容器和元素element, 1对1隧道绑定。</strong></p>
<p>​					<strong>小写变大写：toUpperCase()</strong></p>
<p>​					<strong>取当前时间：Date.now()</strong></p>
<p>​				</p>
<h6 id="测试项目"><a href="#测试项目" class="headerlink" title="测试项目"></a>测试项目</h6><p>​	Vscode里面安装 live server 插件 ，然后在html文档上右键，运行live server。</p>
<h2 id="引入Vue"><a href="#引入Vue" class="headerlink" title="引入Vue"></a>引入Vue</h2><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span> <span class="attr">src</span>=<span class="string">&quot;../js/vue.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span> <span class="attr">src</span>=<span class="string">&quot;../js/jquery.min.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"><span class="title class_">Vue</span>.<span class="property">config</span>.<span class="property">productionTip</span>=<span class="literal">false</span></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="创建Vue实例"><a href="#创建Vue实例" class="headerlink" title="创建Vue实例"></a>创建Vue实例</h2><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    	<span class="keyword">const</span> vm=<span class="keyword">new</span> <span class="title class_">Vue</span></span></span><br><span class="line"><span class="language-javascript">        <span class="variable language_">console</span>.<span class="title function_">log</span>(vm)</span></span><br><span class="line"><span class="language-javascript">    </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="id选择器"><a href="#id选择器" class="headerlink" title="id选择器"></a>id选择器</h2><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;aaa&quot;</span>&gt;</span></span><br><span class="line">    </span><br><span class="line">	<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    </span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    	<span class="keyword">new</span> <span class="title class_">Vue</span>(&#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">el</span>:<span class="string">&quot;#aaa&quot;</span></span></span><br><span class="line"><span class="language-javascript">        &#125;)</span></span><br><span class="line"><span class="language-javascript">    </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="class选择器"><a href="#class选择器" class="headerlink" title="class选择器"></a>class选择器</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;</span><br><span class="line">	new Vue(&#123;</span><br><span class="line">        el:&quot;.aaa&quot;</span><br><span class="line">    &#125;)</span><br><span class="line">&lt;/script&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="插值语法"><a href="#插值语法" class="headerlink" title="插值语法"></a>插值语法</h2><p>一般用于标签体内容</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&#123;&#123;name&#125;&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="指令语法"><a href="#指令语法" class="headerlink" title="指令语法"></a>指令语法</h2><p>一般用于解析标签</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">v-bind:name=&quot;name&quot;</span><br><span class="line">可以简写成</span><br><span class="line">:name=&quot;name&quot;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>Vue中有很多的指令。</p>
<h2 id="数据绑定"><a href="#数据绑定" class="headerlink" title="数据绑定"></a>数据绑定</h2><p>单向绑定： v-bind:     数据–》DOM</p>
<p>双向绑定： v-model:   数据《–》DOM</p>
<p>说明： v-model：一般用于表单类标签，都有value这个key才行。</p>
<p>​		单向简写：<input type="text"     :value="name"><br></p>
<pre><code>    双向简写：&lt;input type=&quot;text&quot; v-model    =&quot;name&quot;&gt;&lt;br&gt;
</code></pre>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">单向绑定：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span>  <span class="attr">v-bind:value</span>=<span class="string">&quot;name&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">双向绑定：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">v-model:value</span>=<span class="string">&quot;name&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line"></span><br><span class="line">单向简写：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span>        <span class="attr">:value</span>=<span class="string">&quot;name&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">双向简写：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">v-model</span>      =<span class="string">&quot;name&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="理解Vue实例和DOM"><a href="#理解Vue实例和DOM" class="headerlink" title="理解Vue实例和DOM"></a>理解Vue实例和DOM</h2><p>​		Vue实例相当如数据库，可以进行编程的数据库; Dom就是一个展示区域。</p>
<p>​		Dom和Vue,只能1对1。</p>
<p>​		Dom把模板给到Vue，Vue进行解析，生成新的页面，mount回Dom区域。</p>
<h2 id="延迟映射VueDOM"><a href="#延迟映射VueDOM" class="headerlink" title="延迟映射VueDOM"></a>延迟映射VueDOM</h2><pre><code>     原型：	   proto
</code></pre>
<p>​		new对象： const  vm &#x3D; new Vue()</p>
<p>​		在vm对象上找不到的属性，会向外层找。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-handlebars"><span class="language-xml"></span></span></span><br><span class="line"><span class="language-xml"><span class="language-handlebars">	const vm = new Vue(&#123;</span></span></span><br><span class="line"><span class="language-xml"><span class="language-handlebars">    &#125;)</span></span></span><br><span class="line"><span class="language-xml"><span class="language-handlebars">    </span></span></span><br><span class="line"><span class="language-xml"><span class="language-handlebars">    <span class="comment">&lt;!-- 定时器1秒后执行 --&gt;</span></span></span></span><br><span class="line"><span class="language-xml"><span class="language-handlebars">    setTimeout(()=&gt;&#123;</span></span></span><br><span class="line"><span class="language-xml"><span class="language-handlebars">    	vm.$mount(&quot;#aaa&quot;)</span></span></span><br><span class="line"><span class="language-xml"><span class="language-handlebars">    &#125;,1000)</span></span></span><br><span class="line"><span class="language-xml"><span class="language-handlebars"></span></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="data对象式写法"><a href="#data对象式写法" class="headerlink" title="data对象式写法"></a>data对象式写法</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">data</span>:&#123;</span><br><span class="line">	<span class="attr">name</span>:<span class="string">&#x27;wangwei&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="date函数式写法"><a href="#date函数式写法" class="headerlink" title="date函数式写法"></a>date函数式写法</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">data</span>:<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">	<span class="comment">//这里this是本vm。 不要用箭头函数，如果用箭头函数就是window了。</span></span><br><span class="line">	<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;-----------&#x27;</span>,<span class="variable language_">this</span>)</span><br><span class="line">	<span class="keyword">return</span>&#123;</span><br><span class="line">		<span class="attr">name</span>:<span class="string">&#x27;wangwei&#x27;</span></span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="date函数式写法-简写"><a href="#date函数式写法-简写" class="headerlink" title="date函数式写法 简写"></a>date函数式写法 简写</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="title function_">data</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="comment">//同上</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="理解MVVM模型"><a href="#理解MVVM模型" class="headerlink" title="理解MVVM模型"></a>理解MVVM模型</h2><p>​		M：  模型model  data</p>
<p>​		V:	  视图view      DOM</p>
<p>​	VM:       视图模型      Vue()	</p>
<h2 id="回顾ES6-定义对象属性"><a href="#回顾ES6-定义对象属性" class="headerlink" title="回顾ES6-定义对象属性"></a>回顾ES6-定义对象属性</h2><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">let</span> person = &#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">name</span>: <span class="string">&#x27;张三&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">sex</span>: <span class="string">&#x27;男&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">        &#125;</span></span><br><span class="line"><span class="language-javascript">        <span class="comment">// 说明：这样添加的对象属性，默认是不参入遍历的。</span></span></span><br><span class="line"><span class="language-javascript">        <span class="title class_">Object</span>.<span class="title function_">defineProperty</span>(person, <span class="string">&#x27;age&#x27;</span>, &#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">value</span>: <span class="number">36</span>,</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">enumerable</span>:<span class="literal">true</span>, <span class="comment">//开启enumerable属性后参与遍历。</span></span></span><br><span class="line"><span class="language-javascript">            <span class="attr">writable</span>:<span class="literal">true</span>,    <span class="comment">//可以修改。</span></span></span><br><span class="line"><span class="language-javascript">            <span class="attr">configurable</span>:<span class="literal">true</span>, <span class="comment">//可以删除 。  </span></span></span><br><span class="line"><span class="language-javascript">        &#125;)</span></span><br><span class="line"><span class="language-javascript">        <span class="comment">// 打印对象的key</span></span></span><br><span class="line"><span class="language-javascript">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">Object</span>.<span class="title function_">keys</span>(person))</span></span><br><span class="line"><span class="language-javascript">        <span class="comment">// 遍历对象</span></span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">for</span>(<span class="keyword">let</span> key <span class="keyword">in</span> person)&#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;abc&quot;</span>,person[key])</span></span><br><span class="line"><span class="language-javascript">        &#125;</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">        <span class="comment">//配置属性</span></span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">let</span> name=<span class="string">&#x27;wangwei&#x27;</span></span></span><br><span class="line"><span class="language-javascript">        <span class="title class_">Object</span>.<span class="title function_">defineProperty</span>(person,<span class="string">&#x27;name2&#x27;</span>,&#123; </span></span><br><span class="line"><span class="language-javascript">            <span class="title function_">get</span>(<span class="params"></span>)&#123;</span></span><br><span class="line"><span class="language-javascript">                <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;有人读取了name2属性了&#x27;</span>)</span></span><br><span class="line"><span class="language-javascript">                <span class="keyword">return</span> name</span></span><br><span class="line"><span class="language-javascript">            &#125;,</span></span><br><span class="line"><span class="language-javascript">            <span class="title function_">set</span>(<span class="params">value</span>)&#123;</span></span><br><span class="line"><span class="language-javascript">                <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;有人修改了name2属性了,且值是&#x27;</span>,value)</span></span><br><span class="line"><span class="language-javascript">                name=value</span></span><br><span class="line"><span class="language-javascript">            &#125;</span></span><br><span class="line"><span class="language-javascript">        &#125;)</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">        <span class="variable language_">console</span>.<span class="title function_">log</span>(person)</span></span><br><span class="line"><span class="language-javascript">    </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="理解数据代理"><a href="#理解数据代理" class="headerlink" title="理解数据代理"></a>理解数据代理</h2><p>​		定义： 通过一个对象obj2代理对另一个对象obj中属性的操作(读&#x2F;写)。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> obj =&#123;<span class="attr">x</span>:<span class="number">100</span>&#125;</span><br><span class="line"><span class="keyword">let</span> obj2=&#123;&#125;</span><br><span class="line"><span class="title class_">Object</span>.<span class="title function_">defineProperty</span>(obj2,<span class="string">&#x27;x&#x27;</span>,&#123;</span><br><span class="line">    <span class="title function_">get</span>(<span class="params"></span>)&#123;</span><br><span class="line">        <span class="keyword">return</span> obj.<span class="property">x</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="title function_">set</span>(<span class="params">value</span>)&#123;</span><br><span class="line">        obj.<span class="property">x</span>=value</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="事件处理"><a href="#事件处理" class="headerlink" title="事件处理"></a>事件处理</h2><h3 id="事件修饰符-点击提示信息"><a href="#事件修饰符-点击提示信息" class="headerlink" title="事件修饰符-点击提示信息"></a>事件修饰符-点击提示信息</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;aaa&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">h2</span>&gt;</span>欢迎来到&#123;&#123;name&#125;&#125;学习<span class="tag">&lt;/<span class="name">h2</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">button</span> <span class="attr">v-on:click</span>=<span class="string">&quot;showInfo&quot;</span>&gt;</span>点我提示信息，简写是@click<span class="tag">&lt;/<span class="name">button</span>&gt;</span>  </span><br><span class="line">        <span class="tag">&lt;<span class="name">button</span> @<span class="attr">click</span>=<span class="string">&quot;show2&quot;</span>&gt;</span>点我提示信息1<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">button</span> @<span class="attr">click</span>=<span class="string">&quot;show3($event,66)&quot;</span>&gt;</span>点我提示信息2<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">new</span> <span class="title class_">Vue</span>(&#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">el</span>: <span class="string">&quot;#aaa&quot;</span>,</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">data</span>: &#123;</span></span><br><span class="line"><span class="language-javascript">                <span class="attr">name</span>: <span class="string">&quot;天然小学&quot;</span>,</span></span><br><span class="line"><span class="language-javascript">            &#125;,</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">methods</span>: &#123;</span></span><br><span class="line"><span class="language-javascript">                <span class="title function_">showInfo</span>(<span class="params"></span>) &#123;</span></span><br><span class="line"><span class="language-javascript">                    <span class="title function_">alert</span>(<span class="string">&#x27;同学你好&#x27;</span>)</span></span><br><span class="line"><span class="language-javascript">                &#125;,</span></span><br><span class="line"><span class="language-javascript">                <span class="title function_">show2</span>(<span class="params"></span>)&#123;</span></span><br><span class="line"><span class="language-javascript">                    <span class="title function_">alert</span>(<span class="string">&#x27;同学你好！！&#x27;</span>)</span></span><br><span class="line"><span class="language-javascript">                &#125;,</span></span><br><span class="line"><span class="language-javascript">                <span class="title function_">show3</span>(<span class="params">enent,number</span>)&#123;</span></span><br><span class="line"><span class="language-javascript">                    <span class="variable language_">console</span>.<span class="title function_">log</span>(event.<span class="property">target</span>.<span class="property">innerText</span>)</span></span><br><span class="line"><span class="language-javascript">                    <span class="title function_">alert</span>(number)</span></span><br><span class="line"><span class="language-javascript">                &#125;</span></span><br><span class="line"><span class="language-javascript">            &#125;</span></span><br><span class="line"><span class="language-javascript">        &#125;)</span></span><br><span class="line"><span class="language-javascript">    </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="事件修饰符-阻止默认行为-prevent"><a href="#事件修饰符-阻止默认行为-prevent" class="headerlink" title="事件修饰符-阻止默认行为 prevent"></a>事件修饰符-阻止默认行为 prevent</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">&quot;http://www.baidu.com&quot;</span> @<span class="attr">click.prevent</span>=<span class="string">&quot;showInfo&quot;</span>&gt;</span>点我只提示不跳转<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="事件修饰符-阻止冒泡-stop"><a href="#事件修饰符-阻止冒泡-stop" class="headerlink" title="事件修饰符-阻止冒泡 stop"></a>事件修饰符-阻止冒泡 stop</h4><h4 id="事件修饰符-只触发一次-once"><a href="#事件修饰符-只触发一次-once" class="headerlink" title="事件修饰符-只触发一次 once"></a>事件修饰符-只触发一次 once</h4><h4 id="事件修饰符-使用事件捕获模式-capture"><a href="#事件修饰符-使用事件捕获模式-capture" class="headerlink" title="事件修饰符-使用事件捕获模式 capture"></a>事件修饰符-使用事件捕获模式 capture</h4><h4 id="事件修饰符-只有enent-target是当前元素触发-self"><a href="#事件修饰符-只有enent-target是当前元素触发-self" class="headerlink" title="事件修饰符-只有enent.target是当前元素触发 self"></a>事件修饰符-只有enent.target是当前元素触发 self</h4><h4 id="事件修饰符-事件的默认行为立即执行不等回调-passive"><a href="#事件修饰符-事件的默认行为立即执行不等回调-passive" class="headerlink" title="事件修饰符-事件的默认行为立即执行不等回调 passive"></a>事件修饰符-事件的默认行为立即执行不等回调 passive</h4><h3 id="键盘事件"><a href="#键盘事件" class="headerlink" title="键盘事件"></a>键盘事件</h3><p>Vue中常用的按键别名：</p>
<p>​	回车 enter</p>
<p>​	删除 delte</p>
<p>​	退出 esc</p>
<p>​	空格 space</p>
<p>​	换行 tab</p>
<p>​	上 up</p>
<p>​	下 down</p>
<p>​	左 left</p>
<p>​	右 right</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;aaa&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">placeholder</span>=<span class="string">&quot;按下按键显示安检名字和编码&quot;</span> @<span class="attr">keydown</span>=<span class="string">&quot;showKey&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">placeholder</span>=<span class="string">&quot;按下回车显示输入&quot;</span> @<span class="attr">keyup.enter</span>=<span class="string">&quot;showInfo&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">p</span>&gt;</span>This is a paragraph <span class="tag">&lt;<span class="name">span</span> <span class="attr">style</span>=<span class="string">&quot;color:#00ff00;&quot;</span>&gt;</span>This is a paragraph<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">            This is a paragraph<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">new</span> <span class="title class_">Vue</span>(&#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">el</span>:<span class="string">&quot;#aaa&quot;</span>,</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">methods</span>:&#123;</span></span><br><span class="line"><span class="language-javascript">                <span class="title function_">showKey</span>(<span class="params">e</span>)&#123;</span></span><br><span class="line"><span class="language-javascript">                    <span class="variable language_">console</span>.<span class="title function_">log</span>(e.<span class="property">key</span>,e.<span class="property">keyCode</span>)</span></span><br><span class="line"><span class="language-javascript">                &#125;,</span></span><br><span class="line"><span class="language-javascript">                <span class="title function_">showInfo</span>(<span class="params">e</span>)&#123;</span></span><br><span class="line"><span class="language-javascript">                    <span class="variable language_">console</span>.<span class="title function_">log</span>(e.<span class="property">target</span>.<span class="property">value</span>)</span></span><br><span class="line"><span class="language-javascript">                &#125;</span></span><br><span class="line"><span class="language-javascript">            &#125;</span></span><br><span class="line"><span class="language-javascript">        &#125;)</span></span><br><span class="line"><span class="language-javascript">    </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="按键别名"><a href="#按键别名" class="headerlink" title="按键别名"></a>按键别名</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="title class_">Vue</span>.<span class="property">config</span>.<span class="property">keyCodes</span>.<span class="property">wangweihuiche</span> = <span class="number">13</span> ;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="methods"><a href="#methods" class="headerlink" title="methods"></a>methods</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">methods</span>:&#123;</span><br><span class="line">    <span class="title function_">f01</span>(<span class="params"></span>)&#123;</span><br><span class="line">        </span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="title function_">f02</span>(<span class="params"></span>)&#123;</span><br><span class="line">        </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="computed"><a href="#computed" class="headerlink" title="computed"></a>computed</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">computed</span>:&#123;</span><br><span class="line">    <span class="attr">value01</span>:&#123;</span><br><span class="line">        <span class="title function_">get</span>(<span class="params"></span>)&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="variable language_">this</span>.<span class="property">firstName</span>+<span class="string">&#x27;-&#x27;</span>+<span class="variable language_">this</span>.<span class="property">lastName</span></span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="title function_">set</span>(<span class="params">value</span>)&#123;</span><br><span class="line">            cost arr = value.<span class="title function_">split</span>(<span class="string">&#x27;-&#x27;</span>)</span><br><span class="line">            <span class="variable language_">this</span>.<span class="property">firstName</span>=arr[<span class="number">0</span>]</span><br><span class="line">            <span class="variable language_">this</span>.<span class="property">lastName</span>=arr[<span class="number">1</span>]</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//只读不改的计算属性,可以简写如下:</span></span><br><span class="line">    <span class="title function_">value02</span>(<span class="params"></span>)&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="variable language_">this</span>.<span class="property">firstName</span>+<span class="string">&#x27;-&#x27;</span>+<span class="variable language_">this</span>.<span class="property">lastName</span> </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h1 id="Axios-四-跨域请求"><a href="#Axios-四-跨域请求" class="headerlink" title="Axios(四):跨域请求"></a>Axios(四):跨域请求</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br></pre></td><td class="code"><pre><span class="line">https://blog.csdn.net/xuedajing030409/article/details/117555460</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">XueJing11111111</span><br><span class="line">于 2021-06-04 11:54:58 发布 677</span><br><span class="line">收藏</span><br><span class="line">版权</span><br><span class="line"></span><br><span class="line">在前后端开发过程中一直会伴随我们的问题就是跨域问题，因为这时候前端和后端的代码是在不同机器上运行的，两个地址不在一个域名下，这个时候前端脚本在进行axios访问的时候浏览器就会报跨域相关的错误。</span><br><span class="line"></span><br><span class="line">原因：浏览器的同源策略不允许跨域访问，所谓同源策略是指协议、域名、端口相同。</span><br><span class="line">1. 设置代理服务器,实现跨域请求转发</span><br><span class="line"></span><br><span class="line">方案：采用proxyTable解决。</span><br><span class="line"></span><br><span class="line">    proxyTable是什么？</span><br><span class="line"></span><br><span class="line">    vue-cli提供的解决vue开发环境下跨域问题的方法，proxyTable的底层使用了http-proxy-middleware,它是http代理中间件，它依赖node.js，基本原理是用服务端代理解决浏览器跨域</span><br><span class="line"></span><br><span class="line">    实现的过程就是在我们前端的本地起一个服务，然后我们前端的所有ajax访问首选访问我们本地的服务，本地的服务不会对来的请求做加工处理，只是将请求转发到我们真实的后台服务上去。我们本地的服务其实你就是一个中转站。这种解决方案就是利用后端之间访问是不存在跨域的问题。</span><br><span class="line"></span><br><span class="line">    具体流程</span><br><span class="line"></span><br><span class="line">        首先在config/index.js里面找到proxyTable:&#123;&#125;,然后在里面加入</span><br><span class="line"></span><br><span class="line">            &quot;/api&quot;:&#123;</span><br><span class="line">                target: &#x27;https://www.runoob.com&#x27;,</span><br><span class="line">                changeOrigin: true,</span><br><span class="line">                pathRewrite:&#123;</span><br><span class="line">                    &#x27;^/api&#x27;:&#x27;&#x27;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            注意:</span><br><span class="line"></span><br><span class="line">            /api: 是自定义的，写成什么都可以。</span><br><span class="line"></span><br><span class="line">            target: 设置要调用的接口域名和端口号。</span><br><span class="line"></span><br><span class="line">            ^/api: 代替target里面的地址，后面组件中我们调接口时直接用/api代替</span><br><span class="line"></span><br><span class="line">        在组件中实现跨域请求</span><br><span class="line"></span><br><span class="line">            比如要访问&#x27;https://www.runoob.com/ajax/json_demo.json&#x27;，直接写/api/ajax/json_demo.json即可。</span><br><span class="line"></span><br><span class="line">                import axios from &#x27;axios&#x27;</span><br><span class="line">                 </span><br><span class="line">                axios.get(&#x27;/api/ajax/json_demo.json&#x27;)</span><br><span class="line">                    .then(resp=&gt;&#123;</span><br><span class="line">                        console.log(resp.data)</span><br><span class="line">                    &#125;)</span><br><span class="line">                    .cath(err=&gt;&#123;</span><br><span class="line">                        console.log(err)</span><br><span class="line">                    &#125;)</span><br><span class="line"></span><br><span class="line">            然而我们可以在src/main.js设置一个基础路径，这样你调用接口的时候可以不写api,直接写/ajax/json_demo.json即可。</span><br><span class="line"></span><br><span class="line">                在src/main.js设置axios.defaults.baseURL=&quot;/api&quot;;</span><br><span class="line"></span><br><span class="line">                    import axios from &#x27;axios&#x27;</span><br><span class="line">                    axios.defaults.baseURL=&quot;/api&quot;;</span><br><span class="line"></span><br><span class="line">                在组件中直接调用接口即可。</span><br><span class="line"></span><br><span class="line">                    import axios from &#x27;axios&#x27;</span><br><span class="line">                     </span><br><span class="line">                    axios.get(&#x27;/ajax/json_demo.json&#x27;)</span><br><span class="line">                        .then(resp=&gt;&#123;</span><br><span class="line">                            console.log(resp.data)</span><br><span class="line">                        &#125;)</span><br><span class="line">                        .cath(err=&gt;&#123;</span><br><span class="line">                            console.log(err)</span><br><span class="line">                        &#125;)</span><br><span class="line"></span><br><span class="line">                2. 在后台django中配置跨域请求允许</span><br><span class="line"></span><br><span class="line">但是今天我们这里不讲这种方式，有兴趣的可以在我的另一篇博客看到</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h1 id="Vue后台-–-引入markdown编辑器及新增文章"><a href="#Vue后台-–-引入markdown编辑器及新增文章" class="headerlink" title="Vue后台 – 引入markdown编辑器及新增文章"></a>Vue后台 – 引入markdown编辑器及新增文章</h1><p>官方文档示例演示：vuejs.org&#x2F;v2&#x2F;examples&#x2F;index.html</p>
<p>示例代码： <a target="_blank" rel="noopener" href="https://github.com/vuejs/v2.vuejs.org/tree/master/src/v2/examples/vue-20-markdown-editor">https://github.com/vuejs/v2.vuejs.org/tree/master/src/v2/examples/vue-20-markdown-editor</a></p>
<p>使用markdownit： <a target="_blank" rel="noopener" href="https://github.com/markdown-it/markdown-it">https://github.com/markdown-it/markdown-it</a></p>
<p><a target="_blank" rel="noopener" href="https://markdown-it.docschina.org/api/MarkdownIt.html">https://markdown-it.docschina.org/api/MarkdownIt.html</a></p>
<p><img src="C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\1662134398802.png" alt="1662134398802"></p>
<h3 id="（6）引入-Element"><a href="#（6）引入-Element" class="headerlink" title="（6）引入 Element"></a>（6）引入 Element</h3><h4 id="样式文件需要单独引入，直接使用完整引入吧，在-main-js-里写入引用内容"><a href="#样式文件需要单独引入，直接使用完整引入吧，在-main-js-里写入引用内容" class="headerlink" title="样式文件需要单独引入，直接使用完整引入吧，在 main.js 里写入引用内容"></a>样式文件需要单独引入，直接使用完整引入吧，在 main.js 里写入引用内容</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">Vue</span> <span class="keyword">from</span> <span class="string">&#x27;vue&#x27;</span></span><br><span class="line"><span class="keyword">import</span> <span class="title class_">App</span> <span class="keyword">from</span> <span class="string">&#x27;./App&#x27;</span></span><br><span class="line"><span class="keyword">import</span> router <span class="keyword">from</span> <span class="string">&#x27;./router&#x27;</span></span><br><span class="line"><span class="keyword">import</span> <span class="title class_">ElementUI</span> <span class="keyword">from</span> <span class="string">&#x27;element-ui&#x27;</span>;    <span class="comment">// （1）</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">&#x27;element-ui/lib/theme-chalk/index.css&#x27;</span>;    <span class="comment">// （2）</span></span><br><span class="line"></span><br><span class="line"><span class="title class_">Vue</span>.<span class="property">config</span>.<span class="property">productionTip</span> = <span class="literal">false</span></span><br><span class="line"><span class="title class_">Vue</span>.<span class="title function_">use</span>(<span class="title class_">ElementUI</span>, &#123; <span class="attr">size</span>: <span class="string">&#x27;small&#x27;</span>, <span class="attr">zIndex</span>: <span class="number">3000</span> &#125;)  </span><br><span class="line"><span class="comment">// （3）在引入 Element 时，可以传入一个全局配置对象。该对象目前支持 size 与 zIndex 字段。size 用于改变组件的默认尺寸，zIndex 设置弹框的初始 z-index（默认值：2000）</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">new</span> <span class="title class_">Vue</span>(&#123;</span><br><span class="line">  <span class="attr">el</span>: <span class="string">&#x27;#app&#x27;</span>,</span><br><span class="line">  router,</span><br><span class="line">  <span class="attr">components</span>: &#123; <span class="title class_">App</span> &#125;,</span><br><span class="line">  <span class="attr">template</span>: <span class="string">&#x27;&lt;App/&gt;&#x27;</span>,</span><br><span class="line">  <span class="attr">render</span>: <span class="function"><span class="params">h</span> =&gt;</span> <span class="title function_">h</span>(<span class="title class_">App</span>)  <span class="comment">// （4）</span></span><br><span class="line">&#125;)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="以上便完成了-element-ui-在-vue-cli-项目中的引入！"><a href="#以上便完成了-element-ui-在-vue-cli-项目中的引入！" class="headerlink" title="以上便完成了 element-ui 在 vue-cli 项目中的引入！"></a>以上便完成了 element-ui 在 vue-cli 项目中的引入！</h4><h3 id="（7）补充内容"><a href="#（7）补充内容" class="headerlink" title="（7）补充内容"></a>（7）补充内容</h3><h4 id="为了体现模块化，可以建立一个文件来引入-element-ui-的样式文件"><a href="#为了体现模块化，可以建立一个文件来引入-element-ui-的样式文件" class="headerlink" title="为了体现模块化，可以建立一个文件来引入 element-ui 的样式文件"></a>为了体现模块化，可以建立一个文件来引入 element-ui 的样式文件</h4><p>比如 plugins -&gt; element.js ，写如下代码</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">Vue</span> <span class="keyword">from</span> <span class="string">&#x27;vue&#x27;</span></span><br><span class="line"><span class="keyword">import</span> <span class="title class_">ElementUI</span> <span class="keyword">from</span> <span class="string">&#x27;element-ui&#x27;</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">&#x27;element-ui/lib/theme-chalk/index.css&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="title class_">Vue</span>.<span class="title function_">use</span>(<span class="title class_">ElementUI</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>在 main.js 中</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">Vue</span> <span class="keyword">from</span> <span class="string">&#x27;vue&#x27;</span></span><br><span class="line"><span class="keyword">import</span> <span class="title class_">App</span> <span class="keyword">from</span> <span class="string">&#x27;./App&#x27;</span></span><br><span class="line"><span class="keyword">import</span> router <span class="keyword">from</span> <span class="string">&#x27;./router&#x27;</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">&#x27;./plugins/element.js&#x27;</span>  <span class="comment">// （1）</span></span><br><span class="line"></span><br><span class="line"><span class="title class_">Vue</span>.<span class="property">config</span>.<span class="property">productionTip</span> = <span class="literal">false</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">new</span> <span class="title class_">Vue</span>(&#123;</span><br><span class="line">  <span class="attr">el</span>: <span class="string">&#x27;#app&#x27;</span>,</span><br><span class="line">  router,</span><br><span class="line">  <span class="attr">components</span>: &#123; <span class="title class_">App</span> &#125;,</span><br><span class="line">  <span class="attr">template</span>: <span class="string">&#x27;&lt;App/&gt;&#x27;</span>,</span><br><span class="line">  <span class="attr">render</span>: <span class="function"><span class="params">h</span> =&gt;</span> <span class="title function_">h</span>(<span class="title class_">App</span>)     <span class="comment">// （2）</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>​        </p>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/vue/" rel="tag">vue</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%9F%BA%E7%A1%80/" rel="tag">基础</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
    <article
  id="post-GBase8s安装部署规范"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/05/10/GBase8s%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2%E8%A7%84%E8%8C%83/"
    >GBase8s安装部署规范</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/05/10/GBase8s%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2%E8%A7%84%E8%8C%83/" class="article-date">
  <time datetime="2023-05-10T00:54:56.000Z" itemprop="datePublished">2023-05-10</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/GBase8s/">GBase8s</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h2 id="数据库版本"><a href="#数据库版本" class="headerlink" title="数据库版本"></a>数据库版本</h2><p>GBase8sV8.7_AEE_2.0.1A2_6_7b5949_RHEL6_x86_64.tar       </p>
<p>​	说明： </p>
<p>​		1、2020年03月10日发版</p>
<p>​		2、MD5值为：  04a49447cfab89b3748f82f22c08ea77</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[gbasedbt@wei3 ~]$ onstat -V</span><br><span class="line">GBase Database Server Version 12.10.FC4G1AEE_2.0.1A2_6_7b5949 Software Serial Number AAA#B000000</span><br><span class="line">[gbasedbt@wei3 ~]$ onstat -version</span><br><span class="line">Program Name:           onstat</span><br><span class="line">Build Number:           2.0.1A2_6_7b5949_N303</span><br><span class="line">Build Host:             redhat</span><br><span class="line">Build OS:               Linux 2.6.32-358.el6.x86_64</span><br><span class="line">Build Date:             Tue Mar 10 12:13:20 CST 2020</span><br><span class="line">Build Timestamp:        10-Mar-2020.12:00:40UTC-06</span><br><span class="line">GLS Version:            glslib-6.00.FC5</span><br><span class="line">[gbasedbt@wei3 ~]$ </span><br></pre></td></tr></table></figure>



<h2 id="数据库jdbc驱动版本"><a href="#数据库jdbc驱动版本" class="headerlink" title="数据库jdbc驱动版本"></a>数据库jdbc驱动版本</h2><p>gbasedbtjdbc_a2_6.jar</p>
<p>​	说明： </p>
<p>​		1、2020年03月10日发版</p>
<p>​		2、MD5值为：  c1a443ab09e700971886099380844e85</p>
<h2 id="安装规范"><a href="#安装规范" class="headerlink" title="安装规范"></a>安装规范</h2><h3 id="关闭防火墙"><a href="#关闭防火墙" class="headerlink" title="关闭防火墙"></a>关闭防火墙</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">系统工程师决定-可选</span></span><br><span class="line">service firewalld stop</span><br><span class="line">chkconfig firewalld off</span><br><span class="line">systemctl status firewalld.service</span><br><span class="line">systemctl stop firewalld.service</span><br><span class="line">systemctl disable firewalld.service</span><br><span class="line">systemctl list-unit-files （chkconfig --list 弃用）</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">centos6按如下方法关闭</span></span><br><span class="line">service iptables stop</span><br><span class="line">chkconfig iptables off</span><br></pre></td></tr></table></figure>

<h3 id="关闭DNS"><a href="#关闭DNS" class="headerlink" title="关闭DNS"></a>关闭DNS</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">系统工程师决定-可选</span></span><br><span class="line">sed -i &quot;s#^hosts.*#hosts:      files#g&quot; /etc/nsswitch.conf</span><br></pre></td></tr></table></figure>

<h3 id="修改ulimit内核参数"><a href="#修改ulimit内核参数" class="headerlink" title="修改ulimit内核参数"></a>修改ulimit内核参数</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">系统工程师决定-可选</span></span><br><span class="line">[root@localhost ~]#vi /etc/security/limits.conf</span><br><span class="line">gbasedbt soft nproc 65535</span><br><span class="line">gbasedbt hard nproc 65535</span><br><span class="line">gbasedbt soft nofile 1048576</span><br><span class="line">gbasedbt hard nofile 1048576</span><br><span class="line">[root@localhost ~]#ulimit -a</span><br></pre></td></tr></table></figure>

<h3 id="修改内核参数"><a href="#修改内核参数" class="headerlink" title="修改内核参数"></a>修改内核参数</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">系统工程师决定-可选</span></span><br><span class="line">[root@wei3 ~]# vi /etc/sysctl.conf </span><br><span class="line">fs.aio-max-nr=3145728         </span><br><span class="line">kernel.shmmax=4398046511104   </span><br><span class="line">kernel.shmall=4294967296      </span><br><span class="line">kernel.shmmni=4096			  </span><br><span class="line">kernel.sem=250 32000 100 142 </span><br><span class="line">[root@wei3 ~]# sysctl -p</span><br></pre></td></tr></table></figure>

<h3 id="上传介质"><a href="#上传介质" class="headerlink" title="上传介质"></a>上传介质</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[root@wei3 sanxiajichang]# cd /opt/soft/gbase/sanxiajichang</span><br><span class="line">[root@wei3 sanxiajichang]# ls -lrt</span><br><span class="line">total 309944</span><br><span class="line">-rw-rw-rw-. 1 root root 316211200 Aug 12 16:58 GBase8sV8.7_AEE_2.0.1A2_6_7b5949_RHEL6_x86_64.tar</span><br><span class="line">-rw-rw-rw-. 1 root root   1169489 Aug 12 16:58 gbasedbtjdbc_a2_6.jar</span><br><span class="line">[root@wei3 sanxiajichang]# </span><br></pre></td></tr></table></figure>

<h3 id="解压介质"><a href="#解压介质" class="headerlink" title="解压介质"></a>解压介质</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">[root@wei3 sanxiajichang]# ls</span><br><span class="line">GBase8sV8.7_AEE_2.0.1A2_6_7b5949_RHEL6_x86_64.tar  gbasedbtjdbc_a2_6.jar</span><br><span class="line">[root@wei3 sanxiajichang]# mkdir server</span><br><span class="line">[root@wei3 sanxiajichang]# cd server/</span><br><span class="line">[root@wei3 server]# mv ../GBase8sV8.7_AEE_2.0.1A2_6_7b5949_RHEL6_x86_64.tar ./</span><br><span class="line">[root@wei3 server]# tar xvf GBase8sV8.7_AEE_2.0.1A2_6_7b5949_RHEL6_x86_64.tar </span><br><span class="line">ids_install</span><br><span class="line">onsecurity</span><br><span class="line">doc/</span><br><span class="line">doc/ids_unix_relnotes_12.10.html</span><br><span class="line">doc/ids_machine_notes_12.10.txt</span><br><span class="line">ids.properties</span><br><span class="line">.gbase.properties</span><br><span class="line">[root@wei3 server]# </span><br><span class="line">[root@wei3 server]# ls -lrt</span><br><span class="line">total 617572</span><br><span class="line">drwxr-xr-x. 2 root root        77 Mar 10  2020 doc</span><br><span class="line">-rwxr-xr-x. 1 root root     81782 Mar 10  2020 onsecurity</span><br><span class="line">-rw-r--r--. 1 root root      1864 Mar 10  2020 ids.properties</span><br><span class="line">-rwxr-xr-x. 1 root root 316095510 Mar 10  2020 ids_install</span><br><span class="line">-rw-rw-rw-. 1 root root 316211200 Aug 12 16:58 GBase8sV8.7_AEE_2.0.1A2_6_7b5949_RHEL6_x86_64.tar</span><br><span class="line">[root@wei3 server]# </span><br></pre></td></tr></table></figure>

<h3 id="创建用户"><a href="#创建用户" class="headerlink" title="创建用户"></a>创建用户</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">groupadd gbasedbt -g 500</span><br><span class="line">useradd  gbasedbt -u 500 -g gbasedbt -m -d /home/gbasedbt</span><br><span class="line">passwd gbasedbt #设置密码为 GBase123</span><br></pre></td></tr></table></figure>

<h3 id="安装软件"><a href="#安装软件" class="headerlink" title="安装软件"></a>安装软件</h3><p>​	说明：	</p>
<p>​				1、今后统一安装到 &#x2F;opt&#x2F;gbase 目录。</p>
<p>​				2、选择 2- No - do not create an instance 不要创建实例。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br></pre></td><td class="code"><pre><span class="line">[root@wei3 server]# ls</span><br><span class="line">doc  GBase8sV8.7_AEE_2.0.1A2_6_7b5949_RHEL6_x86_64.tar  ids_install  ids.properties  onsecurity</span><br><span class="line">[root@wei3 server]# </span><br><span class="line">[root@wei3 server]# ./ids_install </span><br><span class="line">Preparing to install...</span><br><span class="line">Extracting the JRE from the installer archive...</span><br><span class="line">Unpacking the JRE...</span><br><span class="line">Extracting the installation resources from the installer archive...</span><br><span class="line">Configuring the installer for this system&#x27;s environment...</span><br><span class="line"></span><br><span class="line">Launching installer...</span><br><span class="line"></span><br><span class="line">===============================================================================</span><br><span class="line">GBase Software Bundle                            (created with InstallAnywhere)</span><br><span class="line">-------------------------------------------------------------------------------</span><br><span class="line"></span><br><span class="line">Preparing CONSOLE Mode Installation...</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">===============================================================================</span><br><span class="line">Getting Started</span><br><span class="line">---------------</span><br><span class="line"></span><br><span class="line">This application  will guide you through the installation of GBase Software </span><br><span class="line">Bundle.</span><br><span class="line">Copyright General Data Corporation 2014, 2022. All rights reserved.</span><br><span class="line"></span><br><span class="line">1. Release Notes</span><br><span class="line">The Release Notes can be found in </span><br><span class="line">/opt/soft/gbase/sanxiajichang/server/doc/ids_unix_relnotes_12.10.html.</span><br><span class="line">2. Launch Information Center</span><br><span class="line">Access the GBase Information Center at http://www.gbase.cn.</span><br><span class="line">To Begin Installation, respond to each prompt to proceed to the next step in </span><br><span class="line">the installation.</span><br><span class="line">If you want to change something on a previous step, type &#x27;back&#x27;.</span><br><span class="line">You may cancel this installation at any time by typing &#x27;quit&#x27;.</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">PRESS &lt;ENTER&gt; TO CONTINUE: </span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">===============================================================================</span><br><span class="line">License Agreement</span><br><span class="line">-----------------</span><br><span class="line"></span><br><span class="line">Installation and Use of GBase Software Bundle Requires Acceptance of the </span><br><span class="line">Following License Agreement:</span><br><span class="line"></span><br><span class="line">Thank you for choosing GBase product!</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">Please read carefully the following licencing agreement before installing any </span><br><span class="line">product: TIANJIN GENERAL DATA TECHNOLOGY CO. LTD. LICENSE AGREEMENT</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">READ THE TERMS OF THIS AGREEMENT AND ANY PROVIDED SUPPLEMENTAL LICENSETERMS  </span><br><span class="line">(COLLECTIVELY &quot;AGREEMENT&quot;) CAREFULLY BEFORE OPENING THE SOFTWAREMEDIA PACKAGE. </span><br><span class="line">BY OPENING THE SOFTWARE MEDIA PACKAGE, YOU AGREE TO THE TERMS OF THIS </span><br><span class="line">AGREEMENT.  IF YOU ARE ACCESSING THE SOFTWARE ELECTRONICALLY, INDICATE YOUR </span><br><span class="line">ACCEPTANCE OF THESE  TERMS. IF YOU DO NOT AGREE TO ALL THESE TERMS, PROMPTLY </span><br><span class="line">RETURN THE UNUSED  SOFTWARE TO YOUR PLACE OF PURCHASE FOR A REFUND.</span><br><span class="line"></span><br><span class="line">1. LICENSE TO USE. GeneralData grants you a non-exclusive and non-transferable </span><br><span class="line">license for  the internal use only of the accompanying software and </span><br><span class="line">documentation and any error corrections  provided by GeneralData(collectively </span><br><span class="line">&quot;Software&quot;), by the number of users and the class of  computer hardware for </span><br><span class="line">which the corresponding fee has been paid.</span><br><span class="line"></span><br><span class="line">2. RESTRICTIONS. Software is confidential and copyrighted. Title to Software </span><br><span class="line"></span><br><span class="line">PRESS &lt;ENTER&gt; TO CONTINUE: </span><br><span class="line"></span><br><span class="line">and all  associated intellectual property rights is retained by GeneralData </span><br><span class="line">and/or its licensors. Except as  specifically authorized in any Supplemental </span><br><span class="line">License Terms, you may not make copies of Software,  other than a single copy </span><br><span class="line">of Software for archival purposes. Unless enforcement is prohibited by  </span><br><span class="line">applicable law, you may not modify, decompile, or reverse engineer Software. </span><br><span class="line">You acknowledge  that Software is not designed, licensed or intended for use in</span><br><span class="line">the design, construction, operation  or maintenance of any nuclear facility. </span><br><span class="line">GeneralData disclaims any express or implied warranty  of fitness for such </span><br><span class="line">uses. No right, title or interest in or to any trademark, service mark, logo or</span><br><span class="line">trade name of GeneralData or its licensors is granted under this Agreement.</span><br><span class="line"></span><br><span class="line">3. DISCLAIMER OF WARRANTY. Unless specified in this agreement, all express of </span><br><span class="line">implied  conditions, representations and warranties, including any implied </span><br><span class="line">warranty of merchantability,  fitness for aparticular purpose or </span><br><span class="line">non-infringement are disclaimed, except to theextent that  these disclaimers </span><br><span class="line">are held to be legally invalid.</span><br><span class="line"></span><br><span class="line">4. LIMITATION OF LIABILITY. To the extent not prohibited by law, in no event </span><br><span class="line">will GeneralData  or its licensors be liable for any lost revenue, profit or </span><br><span class="line">data, or for special, indirect,  consequential, incidental orpunitive damages, </span><br><span class="line">however caused regardless of the theory of liability,  arising out of or </span><br><span class="line">related to the use of or inability to use software, even if GeneralData has </span><br><span class="line"></span><br><span class="line">PRESS &lt;ENTER&gt; TO CONTINUE: </span><br><span class="line"></span><br><span class="line">been  advised of the possibility of such damages. In no event will </span><br><span class="line">GeneralData&#x27;s libility to you, whether  incontract, tort(including negligence),</span><br><span class="line">or otherwise, exceed the amount paid by you for Software  under this Agreement.</span><br><span class="line">The foregoing limitations will apply even if the above stated warranty  fails </span><br><span class="line">of itsessential purpose.</span><br><span class="line"></span><br><span class="line">5. TERMINATION. This Agreement is effective until terminated. You may terminate</span><br><span class="line">this  Agreement at any time by destroying all copies of Software. This </span><br><span class="line">Agreement will terminate  immediately without noticefrom GeneralData if you </span><br><span class="line">fail to comply with any provision of this  Agreement. Upon Termination, you </span><br><span class="line">must destroy all copies of Software.</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">6. EXPORT REGULATIONS. All Software and technical data delivered under this </span><br><span class="line">Agreement are  subject to US export control laws and may be subject to export </span><br><span class="line">or import regulations in other  countries. You agree to comply strictly with </span><br><span class="line">all such laws and regulations and acknowledge that  you have the responsibility</span><br><span class="line">to obtain such licenses to export, re-export, or import as may be  required </span><br><span class="line">after delivery to you.</span><br><span class="line"></span><br><span class="line">7. CHINESE GOVERNMENT RESTRICTED. If Software is being acquired by or on behalf</span><br><span class="line"></span><br><span class="line">PRESS &lt;ENTER&gt; TO CONTINUE: </span><br><span class="line"></span><br><span class="line">of the  Chinese Government, then the Government&#x27;s rights in Software and </span><br><span class="line">accompanying documentation  will be only as set forth in this Agreement.</span><br><span class="line"></span><br><span class="line">8. GOVERNING LAW. Any action related to this Agreement will be governed by </span><br><span class="line">Chinese law:  &quot;COPYRIGHT LAW OF THE PEOPLE&#x27;S REPUBLIC OF CHINA&quot;, &quot;PATENT LAW OF</span><br><span class="line">THE PEOPLE&#x27;S  REPUBLIC OF CHINA&quot;, &quot;TRADEMARK LAW OF THE PEOPLE&#x27;S REPUBLIC OF </span><br><span class="line">CHINA&quot;, &quot;COMPUTER  SOFTWARE PROTECTION REGULATIONS OF THE PEOPLE&#x27;S REPUBLIC OF </span><br><span class="line">CHINA&quot;. No choice of  law rules of any jurisdiction will apply.&quot;</span><br><span class="line"></span><br><span class="line">9. SEVERABILITY. If any provision of this Agreement is held to be </span><br><span class="line">unenforceable, this  Agreement will remain in effect with the provision </span><br><span class="line">omitted, unless omission would frustrate the  intent of the parties, in which </span><br><span class="line">case this Agreement will immediately terminate.</span><br><span class="line"></span><br><span class="line">10. INTEGRATION. This Agreement is the entire agreement between you and </span><br><span class="line">GeneralData  relating to its subject matter. It supersedes all prior or </span><br><span class="line">contemporaneous oral or written  communications, proposals, representations and</span><br><span class="line">warranties and prevails over any conflicting or  additional terms of any quote,</span><br><span class="line">order, acknowledgment, or other communication between the  parties relating to </span><br><span class="line">its subject matter during the term of this Agreement. No modification of this  </span><br><span class="line">Agreement will be binding, unless in writing and signed by an authorize </span><br><span class="line">depresentative of each  party. When the translation document has the different </span><br><span class="line"></span><br><span class="line">PRESS &lt;ENTER&gt; TO CONTINUE: </span><br><span class="line"></span><br><span class="line">meaning or has the conflicting views with  Chinese original text conflict, </span><br><span class="line">should take the laws and regulations promulgation unit as well as  the </span><br><span class="line">GeneralData issue Chinese original text as the standard.</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">All trademarks and registered trademarks mentioned herein are the  property of </span><br><span class="line">their respective owners.</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">DO YOU ACCEPT THE TERMS OF THIS LICENSE AGREEMENT? (Y/N): y</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">===============================================================================</span><br><span class="line">Installation Location</span><br><span class="line">---------------------</span><br><span class="line"></span><br><span class="line">Choose location for software installation.</span><br><span class="line"></span><br><span class="line">  Default Install Folder: /opt/GBASE/gbase</span><br><span class="line"></span><br><span class="line">ENTER AN ABSOLUTE PATH, OR PRESS &lt;ENTER&gt; TO ACCEPT THE DEFAULT</span><br><span class="line">      : /opt/gbase</span><br><span class="line"></span><br><span class="line">INSTALL FOLDER IS: /opt/gbase</span><br><span class="line">   IS THIS CORRECT? (Y/N): y</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">===============================================================================</span><br><span class="line">Installation or Distribution</span><br><span class="line">----------------------------</span><br><span class="line"></span><br><span class="line">Select the installation type.</span><br><span class="line"></span><br><span class="line">Typical: Install the database server with all features and a database server </span><br><span class="line">that</span><br><span class="line">is configured with default values. Includes:</span><br><span class="line">** Client Software Development Kit (CSDK)</span><br><span class="line">** Java Database Connectivity (JDBC)</span><br><span class="line">Minimum disk space required: 700-800MB</span><br><span class="line"></span><br><span class="line">Custom: Install the database server with specific features and software that </span><br><span class="line">you need.</span><br><span class="line">Optionally install a configured database server instance.</span><br><span class="line">Minimum disk space required: 75 MB (without a server instance)</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">  -&gt;</span><span class="language-bash">1- Typical installation</span></span><br><span class="line">    2- Custom installation</span><br><span class="line">    3- Extract the product files (-DLEGACY option)</span><br><span class="line"></span><br><span class="line">ENTER THE NUMBER FOR YOUR CHOICE, OR PRESS &lt;ENTER&gt; TO ACCEPT THE DEFAULT:: </span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">===============================================================================</span><br><span class="line">Server Instance Creation</span><br><span class="line">------------------------</span><br><span class="line"></span><br><span class="line">Create a server instance?</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">  -&gt;</span><span class="language-bash">1- Yes - create an instance</span></span><br><span class="line">    2- No - do not create an instance</span><br><span class="line"></span><br><span class="line">ENTER THE NUMBER FOR YOUR CHOICE, OR PRESS &lt;ENTER&gt; TO ACCEPT THE DEFAULT:: 2</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">===============================================================================</span><br><span class="line">Installation Summary</span><br><span class="line">--------------------</span><br><span class="line"></span><br><span class="line">Please review the following before continuing:</span><br><span class="line"></span><br><span class="line">Product Name:</span><br><span class="line">    GBase Software Bundle</span><br><span class="line"></span><br><span class="line">Install Folder:</span><br><span class="line">    /opt/gbase</span><br><span class="line"></span><br><span class="line">Product Features:</span><br><span class="line">    GBase database server,</span><br><span class="line">    Base Server,</span><br><span class="line">    Extensions and tools,</span><br><span class="line">    J/Foundation,</span><br><span class="line">    Database extensions,</span><br><span class="line">    Conversion and reversion support,</span><br><span class="line">    XML publishing,</span><br><span class="line">    Demonstration database scripts,</span><br><span class="line">    Enterprise Replication,</span><br><span class="line">    Data loading utilities,</span><br><span class="line">    onunload and onload utilities,</span><br><span class="line">    dbload utility,</span><br><span class="line">    Backup and Restore,</span><br><span class="line">    archecker utility,</span><br><span class="line">    ON-Bar utility,</span><br><span class="line">    Interface to Tivoli Storage Manager,</span><br><span class="line">    Administrative utilities,</span><br><span class="line">    Performance monitoring utilities,</span><br><span class="line">    Miscellaneous monitoring utilities,</span><br><span class="line">    Auditing utilities,</span><br><span class="line">    Database import and export utilities,</span><br><span class="line">    JSON Client Support,</span><br><span class="line">    Global Language Support (GLS),</span><br><span class="line">    Chinese</span><br><span class="line"></span><br><span class="line">Disk Space Information (for Installation Target): </span><br><span class="line">    Required:  494,697,775 Bytes</span><br><span class="line">    Available: 23,135,158,272 Bytes</span><br><span class="line"></span><br><span class="line">PRESS &lt;ENTER&gt; TO CONTINUE: </span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">===============================================================================</span><br><span class="line">Ready To Install</span><br><span class="line">----------------</span><br><span class="line"></span><br><span class="line">InstallAnywhere is now ready to install GBase Software Bundle onto your system </span><br><span class="line">at the following location:</span><br><span class="line"></span><br><span class="line">   /opt/gbase</span><br><span class="line"></span><br><span class="line">PRESS &lt;ENTER&gt; TO INSTALL: </span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">===============================================================================</span><br><span class="line">Installing...</span><br><span class="line">-------------</span><br><span class="line"></span><br><span class="line"> [==================|==================|==================|==================]</span><br><span class="line"> [------------------|------------------|------------------|------------------]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">===============================================================================</span><br><span class="line">Installation Complete</span><br><span class="line">---------------------</span><br><span class="line"></span><br><span class="line">Congratulations! GBase Software Bundle installation is complete.</span><br><span class="line"></span><br><span class="line">Product install status:</span><br><span class="line">GBase: Successful</span><br><span class="line">GBase Connect: Successful</span><br><span class="line"></span><br><span class="line">Main Version: GBase 8s V8.7</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">For more information about using GBase products, see the GBase Information </span><br><span class="line">Center at http://www.gbase.cn.</span><br><span class="line"></span><br><span class="line">PRESS &lt;ENTER&gt; TO EXIT THE INSTALLER: </span><br><span class="line">[root@wei3 server]# </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="配置实例"><a href="#配置实例" class="headerlink" title="配置实例"></a>配置实例</h3><h4 id="环境变量-bash-profile"><a href="#环境变量-bash-profile" class="headerlink" title="环境变量 .bash_profile"></a>环境变量 .bash_profile</h4><p>​		vi &#x2F;home&#x2F;gbasedbt&#x2F;.bash_profile</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">export GBASEDBTDIR=/opt/gbase</span><br><span class="line">export GBASEDBTSERVER=gbase01</span><br><span class="line">export ONCONFIG=onconfig.gbase01</span><br><span class="line">export GBASEDBTSQLHOSTS=$GBASEDBTDIR/etc/sqlhosts.gbase01</span><br><span class="line">export DB_LOCALE=zh_CN.utf8</span><br><span class="line">export CLIENT_LOCALE=zh_CN.utf8</span><br><span class="line">export LD_LIBRARY_PATH=$GBASEDBTDIR/lib:$GBASEDBTDIR/lib/esql:$GBASEDBTDIR/lib/cli:$GBASEDBTDIR/lib/dmi</span><br><span class="line">export PATH=$&#123;GBASEDBTDIR&#125;/bin:$&#123;PATH&#125;:.</span><br><span class="line">export LANG=zh_CN.utf8</span><br><span class="line">export DBDATE=Y4MD-</span><br><span class="line">export GL_USEGLU=1</span><br><span class="line">export BACKUPDIR=/home/gbasedbt/backup/ontape</span><br><span class="line">export DATADIR=/home/gbasedbt/data</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h4 id="监听协议-sqlhosts"><a href="#监听协议-sqlhosts" class="headerlink" title="监听协议 sqlhosts"></a>监听协议 sqlhosts</h4><p>​		说明： IP和端口根据需要修改。</p>
<p>​		vi $GBASEDBTDIR&#x2F;etc&#x2F;sqlhosts.gbase01</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">gbase01 onsoctcp 1.1.1.3 9088 </span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h4 id="数据库存储-chunk"><a href="#数据库存储-chunk" class="headerlink" title="数据库存储 chunk"></a>数据库存储 chunk</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">DATADIR=/home/gbasedbt/data</span><br><span class="line">mkdir $&#123;DATADIR&#125;</span><br><span class="line">touch $&#123;DATADIR&#125;/rootdbs</span><br><span class="line">touch $&#123;DATADIR&#125;/plogdbs</span><br><span class="line">touch $&#123;DATADIR&#125;/llogdbs</span><br><span class="line">touch $&#123;DATADIR&#125;/tmpdbs01</span><br><span class="line">touch $&#123;DATADIR&#125;/tmpdbs02</span><br><span class="line">touch $&#123;DATADIR&#125;/tmpdbs03</span><br><span class="line">touch $&#123;DATADIR&#125;/tmpdbs04</span><br><span class="line">touch $&#123;DATADIR&#125;/datachk01</span><br><span class="line">touch $&#123;DATADIR&#125;/sbchk01</span><br><span class="line">chmod 660 $&#123;DATADIR&#125;/rootdbs</span><br><span class="line">chmod 660 $&#123;DATADIR&#125;/plogdbs</span><br><span class="line">chmod 660 $&#123;DATADIR&#125;/llogdbs</span><br><span class="line">chmod 660 $&#123;DATADIR&#125;/tmpdbs01</span><br><span class="line">chmod 660 $&#123;DATADIR&#125;/tmpdbs02</span><br><span class="line">chmod 660 $&#123;DATADIR&#125;/tmpdbs03</span><br><span class="line">chmod 660 $&#123;DATADIR&#125;/tmpdbs04</span><br><span class="line">chmod 660 $&#123;DATADIR&#125;/datachk01</span><br><span class="line">chmod 660 $&#123;DATADIR&#125;/sbchk01</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h4 id="数据库参数-onconfig"><a href="#数据库参数-onconfig" class="headerlink" title="数据库参数 onconfig"></a>数据库参数 onconfig</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">DATADIR=/home/gbasedbt/data</span><br><span class="line">NUMCPU=`onstat -g osi |awk /&quot;online processors&quot;/&#x27;&#123;print $5-1&#125;&#x27;`</span><br><span class="line">cp $GBASEDBTDIR/etc/onconfig.std  $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">sed -i &quot;s#^ROOTPATH.*#ROOTPATH $&#123;DATADIR&#125;/rootdbs#g&quot; $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">sed -i &quot;s#^ROOTSIZE.*#ROOTSIZE 2048000 #g&quot; $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">sed -i &quot;s#^DBSERVERNAME.*#DBSERVERNAME $GBASEDBTSERVER#g&quot; $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">sed -i &quot;s#^PHYSBUFF.*#PHYSBUFF 4096#g&quot; $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">sed -i &quot;s#^LOGBUFF.*#LOGBUFF 4096#g&quot; $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">sed -i &quot;s#^TAPEDEV.*#TAPEDEV /dev/null#g&quot; $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">sed -i &quot;s#^LTAPEDEV.*#LTAPEDEV /dev/null#g&quot; $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">sed -i &quot;s#^MULTIPROCESSOR.*#MULTIPROCESSOR 1#g&quot; $GBASEDBTDIR/etc/$ONCONFIG;</span><br><span class="line">sed -i &quot;s#^CLEANERS.*#CLEANERS 32#g&quot; $GBASEDBTDIR/etc/$ONCONFIG;</span><br><span class="line">sed -i &quot;s#^LOCKS.*#LOCKS 1000000#g&quot; $GBASEDBTDIR/etc/$ONCONFIG;</span><br><span class="line">sed -i &quot;s#^DEF_TABLE_LOCKMODE.*#DEF_TABLE_LOCKMODE row#g&quot; $GBASEDBTDIR/etc/$ONCONFIG;</span><br><span class="line">sed -i &quot;s#^DS_TOTAL_MEMORY.*#DS_TOTAL_MEMORY 4096000#g&quot; $GBASEDBTDIR/etc/$ONCONFIG;</span><br><span class="line">sed -i &quot;s#^SHMVIRTSIZE.*#SHMVIRTSIZE 4096000#g&quot; $GBASEDBTDIR/etc/$ONCONFIG;</span><br><span class="line">sed -i &quot;s#^SHMADD.*#SHMADD 2048000#g&quot; $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">sed -i &quot;s#^STACKSIZE.*#STACKSIZE 2048#g&quot; $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">sed -i &quot;s#^SBSPACENAME.*#SBSPACENAME sbspace01#g&quot; $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">sed -i &quot;s#^DBSPACETEMP.*#DBSPACETEMP tmpdbs01,tmpdbs02,tmpdbs03,tmpdbs04#g&quot; $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">sed -i &quot;s#^VPCLASS cpu.*#VPCLASS cpu,num=$&#123;NUMCPU&#125;,noage#g&quot; $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">echo &quot;BUFFERPOOL size=8k,buffers=512000,lrus=32,lru_min_dirty=50,lru_max_dirty=60&quot; &gt;&gt;$GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">sed -i &quot;s#^DUMPSHMEM.*#DUMPSHMEM 0#g&quot; $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">sed -i &quot;s#^SYSSBSPACENAME.*#SYSSBSPACENAME sbspace01#g&quot; $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">sed -i &quot;s#^DS_NONPDQ_QUERY_MEM.*#DS_NONPDQ_QUERY_MEM 25600#g&quot; $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">echo &quot;NETTYPE soctcp,4,200,NET&quot; &gt;&gt;$GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>说明： 生产环境用上面的基本上可以了，也可以适当调整。个人测试环境可以再跑一下写明的脚本，把内存少分配点。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">sed -i &quot;s#^SHMVIRTSIZE.*#SHMVIRTSIZE 409600#g&quot; $GBASEDBTDIR/etc/$ONCONFIG;</span><br><span class="line">sed -i &quot;s#^SHMADD.*#SHMADD 204800#g&quot; $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">sed -i &quot;s#^BUFFERPOOL size=8k.*#\#BUFFERPOOL size=8k#g&quot; $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">echo &quot;BUFFERPOOL size=8k,buffers=51200,lrus=32,lru_min_dirty=50,lru_max_dirty=60&quot;&gt;&gt;$GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h3 id="初始化实例"><a href="#初始化实例" class="headerlink" title="初始化实例"></a>初始化实例</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">oninit -ivy</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[gbasedbt@wei3 ~]$ cat $GBASEDBTDIR/tmp/online.log |grep &quot;built successfully&quot;</span><br><span class="line">18:04:25  &#x27;sysmaster&#x27; database built successfully.</span><br><span class="line">18:04:25  &#x27;sysutils&#x27; database built successfully.</span><br><span class="line">18:04:25  &#x27;sysuser&#x27; database built successfully.</span><br><span class="line">18:04:36  &#x27;sysadmin&#x27; database built successfully.</span><br><span class="line">[gbasedbt@wei3 ~]$</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h3 id="关闭实例"><a href="#关闭实例" class="headerlink" title="关闭实例"></a>关闭实例</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">onmode -ky</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h3 id="禁用sysadmin"><a href="#禁用sysadmin" class="headerlink" title="禁用sysadmin"></a>禁用sysadmin</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">touch $GBASEDBTDIR/etc/sysadmin/stop</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h3 id="启动实例"><a href="#启动实例" class="headerlink" title="启动实例"></a>启动实例</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">oninit -v</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h3 id="配置DBSPACES"><a href="#配置DBSPACES" class="headerlink" title="配置DBSPACES"></a>配置DBSPACES</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">onspaces -c -d plogdbs   -p $&#123;DATADIR&#125;/plogdbs   -o 0 -s 5120000</span><br><span class="line">onspaces -c -d llogdbs   -p $&#123;DATADIR&#125;/llogdbs   -o 0 -s 10240000</span><br><span class="line">onspaces -c -d tmpdbs01  -p $&#123;DATADIR&#125;/tmpdbs01  -o 0 -s 10240000 -k 8 -t</span><br><span class="line">onspaces -c -d tmpdbs02  -p $&#123;DATADIR&#125;/tmpdbs02  -o 0 -s 10240000 -k 8 -t</span><br><span class="line">onspaces -c -d tmpdbs03  -p $&#123;DATADIR&#125;/tmpdbs03  -o 0 -s 10240000 -k 8 -t</span><br><span class="line">onspaces -c -d tmpdbs04  -p $&#123;DATADIR&#125;/tmpdbs04  -o 0 -s 10240000 -k 8 -t</span><br><span class="line">onspaces -c -d datadbs01 -p $&#123;DATADIR&#125;/datachk01 -o 0 -s 10240000 -k 8</span><br><span class="line">onspaces -c -S sbspace01 -p $&#123;DATADIR&#125;/sbchk01   -o 0 -s 10240000</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>说明：生产按照上面基本够用，根据实际情况扩容。 个人测试环境存储空间不足可以按照下面配置。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">onspaces -c -d plogdbs   -p $&#123;DATADIR&#125;/plogdbs   -o 0 -s 512000</span><br><span class="line">onspaces -c -d llogdbs   -p $&#123;DATADIR&#125;/llogdbs   -o 0 -s 1024000</span><br><span class="line">onspaces -c -d tmpdbs01  -p $&#123;DATADIR&#125;/tmpdbs01  -o 0 -s 1024000 -k 8 -t</span><br><span class="line">onspaces -c -d tmpdbs02  -p $&#123;DATADIR&#125;/tmpdbs02  -o 0 -s 1024000 -k 8 -t</span><br><span class="line">onspaces -c -d tmpdbs03  -p $&#123;DATADIR&#125;/tmpdbs03  -o 0 -s 1024000 -k 8 -t</span><br><span class="line">onspaces -c -d tmpdbs04  -p $&#123;DATADIR&#125;/tmpdbs04  -o 0 -s 1024000 -k 8 -t</span><br><span class="line">onspaces -c -d datadbs01 -p $&#123;DATADIR&#125;/datachk01 -o 0 -s 1024000 -k 8</span><br><span class="line">onspaces -c -S sbspace01 -p $&#123;DATADIR&#125;/sbchk01   -o 0 -s 1024000</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h3 id="配置逻辑日志"><a href="#配置逻辑日志" class="headerlink" title="配置逻辑日志"></a>配置逻辑日志</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">for i in `seq 100`;do onparams -a -d llogdbs -s 100000;done</span><br><span class="line">for i in `seq 7`;do onmode -l;done</span><br><span class="line">onmode -c</span><br><span class="line">for i in `seq 6`;do onparams -d -l $i -y;done</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h3 id="配置物理日志"><a href="#配置物理日志" class="headerlink" title="配置物理日志"></a>配置物理日志</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">onparams -p -d plogdbs -s 5000000 -y</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>说明：生产按照上面基本够用，根据实际情况扩容。 个人测试环境存储空间不足可以按照下面配置。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">onparams -p -d plogdbs -s 500000 -y</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h3 id="配置逻辑日志备份"><a href="#配置逻辑日志备份" class="headerlink" title="配置逻辑日志备份"></a>配置逻辑日志备份</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">BACKUPDIR=/home/gbasedbt/backup/ontape</span><br><span class="line">mkdir -p $BACKUPDIR</span><br><span class="line">onmode -wf  TAPEDEV=$BACKUPDIR</span><br><span class="line">onmode -wf LTAPEDEV=$BACKUPDIR</span><br><span class="line">onmode -wf  TAPEBLK=2048</span><br><span class="line">onmode -wf LTAPEBLK=2048</span><br><span class="line">sed -i &quot;s#^ALARMPROGRAM.*#ALARMPROGRAM \$GBASEDBTDIR/etc/log_full.sh#g&quot; $GBASEDBTDIR/etc/$ONCONFIG</span><br><span class="line">sed -i &quot;s#^BACKUP_CMD.*#BACKUP_CMD=\&quot;ontape -a -d\&quot; #g&quot; $GBASEDBTDIR/etc/log_full.sh</span><br><span class="line">onmode -ky</span><br><span class="line">oninit -v</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p> 测试逻辑日志备份是否配置成功</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">BACKUPDIR=/home/gbasedbt/backup/ontape</span><br><span class="line">ls -l $BACKUPDIR</span><br><span class="line">onmode -l</span><br><span class="line">onmode -l </span><br><span class="line">onmode -c</span><br><span class="line">ls -l $BACKUPDIR</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h3 id="配置数据库备份"><a href="#配置数据库备份" class="headerlink" title="配置数据库备份"></a>配置数据库备份</h3><h4 id="编写数据库备份脚本"><a href="#编写数据库备份脚本" class="headerlink" title="编写数据库备份脚本"></a>编写数据库备份脚本</h4><p>​		vi &#x2F;home&#x2F;gbasedbt&#x2F;backup&#x2F;backup.sh</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">!/bin/bash</span></span><br><span class="line">. /home/gbasedbt/.bash_profile</span><br><span class="line">onstat - |grep &quot;On-Line&quot; &gt; /dev/null</span><br><span class="line">if [ $? -ne 1 ]</span><br><span class="line">then</span><br><span class="line">DATE=`date`</span><br><span class="line">echo &quot;Level 0 backup of &quot;$GBASEDBTSERVER&quot; strat at &quot;$DATE</span><br><span class="line">ontape -s -L 0</span><br><span class="line">DATE=`date`</span><br><span class="line">echo &quot;Level 0 backup of &quot;$GBASEDBTSERVER&quot; completed at &quot;$DATE</span><br><span class="line">find /home/gbasedbt/backup/ontape -mtime +7 -type f |xargs rm -rf</span><br><span class="line">fi</span><br><span class="line">exit 0</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">chmod 755 /home/gbasedbt/backup/backup.sh</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="定义crontab定时备份数据库"><a href="#定义crontab定时备份数据库" class="headerlink" title="定义crontab定时备份数据库"></a>定义crontab定时备份数据库</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">0 0 * * * /home/gbasedbt/backup/backup.sh &gt;&gt; /home/gbasedbt/backup/backup.log 2&gt;&amp;1</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>说明： gbasedbt用户部署以下定时任务，backup.sh每天0点执行全量备份，同时删除7天以前备份。</p>
<h2 id="创建业务数据库"><a href="#创建业务数据库" class="headerlink" title="创建业务数据库"></a>创建业务数据库</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">su - gbasedbt</span><br><span class="line">dbaccess sysmaster &lt;&lt;!</span><br><span class="line">	create database testdb in datadbs01 with log;</span><br><span class="line">!</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>​	说明： 如果你想查询确认一下数据库的字符集请使用下面的命令</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">dbaccess sysmaster &lt;&lt;!</span><br><span class="line">	select * from sysdatabases;</span><br><span class="line">	select * from sysdbslocale;</span><br><span class="line">!</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>​	说明： </p>
<p>​		zh_CN.57372 对应的是 utf8 字符集。</p>
<p>​		zh_CN.5488   对应的是 zh_cn.GB18030-2000 字符集</p>
<h2 id="建表和查询测试"><a href="#建表和查询测试" class="headerlink" title="建表和查询测试"></a>建表和查询测试</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">dbaccess testdb &lt;&lt;!</span><br><span class="line">drop table if exists user;</span><br><span class="line">create table user (</span><br><span class="line">	id serial(8),</span><br><span class="line">	name varchar(5),</span><br><span class="line">	pwd decimal,</span><br><span class="line">	tm datetime year to second default current  year to second</span><br><span class="line">);</span><br><span class="line">insert into  user(name) values(&#x27;aaa&#x27;);</span><br><span class="line">insert into  user values(2,&#x27;aaa&#x27;,1,current);</span><br><span class="line">insert into  user values(3,&#x27;aaa&#x27;,2,current);</span><br><span class="line">insert into  user values(4,&#x27;aaa&#x27;,3,current);</span><br><span class="line">insert into  user values(5,&#x27;aaa&#x27;,3,&#x27;2022-06-15 20:20:20&#x27;);</span><br><span class="line">insert into  user values(6,&#x27;aaa&#x27;,3,&#x27;2022-06-14 20:20:20&#x27;);</span><br><span class="line">insert into  user values(7,&#x27;aaa&#x27;,3,&#x27;2022-06-13 20:20:20&#x27;);</span><br><span class="line">insert into  user values(8,&#x27;aaa&#x27;,3,&#x27;2022-06-15 15:20:20&#x27;);</span><br><span class="line">!</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">dbaccess testdb &lt;&lt;!</span><br><span class="line">	select * from user;</span><br><span class="line">!</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="修补to-char补丁"><a href="#修补to-char补丁" class="headerlink" title="修补to_char补丁"></a>修补to_char补丁</h2><h3 id="上传补丁到服务器"><a href="#上传补丁到服务器" class="headerlink" title="上传补丁到服务器"></a>上传补丁到服务器</h3><p>​			补丁下载地址：<a target="_blank" rel="noopener" href="https://pan.baidu.com/s/1bsToJrJDwWhpvo0QTQI6FA">https://pan.baidu.com/s/1bsToJrJDwWhpvo0QTQI6FA</a><br>​			提取码：e0ue</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">补丁文件名称和MD5值：</span></span><br><span class="line">[root@wei3 p]# ls -l</span><br><span class="line">total 444</span><br><span class="line">-rw-rw-rw-. 1 root root  44450 Aug 14 08:41 boot1210.sql</span><br><span class="line">-rw-rw-rw-. 1 root root 399080 Aug 14 08:41 liboracle.udr</span><br><span class="line">-rw-rw-rw-. 1 root root    268 Aug 14 08:41 readme.txt</span><br><span class="line">-rw-rw-rw-. 1 root root   1707 Aug 14 08:42 to_char重新注册.sql</span><br><span class="line">[root@wei3 p]# </span><br><span class="line">[root@wei3 p]# md5sum liboracle.udr </span><br><span class="line">330924fe910c234078bde5f252c8a6e4  liboracle.udr</span><br><span class="line">[root@wei3 p]# </span><br><span class="line">[root@wei3 p]# md5sum boot1210.sql </span><br><span class="line">16da724a0e1edf6c7fc4089f0f342fa3  boot1210.sql</span><br><span class="line">[root@wei3 p]# </span><br><span class="line">[root@wei3 p]# pwd</span><br><span class="line">/opt/soft/gbase/sanxiajichang/to_char/p</span><br><span class="line">[root@wei3 p]# </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>​	说明：补丁文件已经随，数据库server，数据库jdbc驱动，一起打包。</p>
<h3 id="关闭数据库"><a href="#关闭数据库" class="headerlink" title="关闭数据库"></a>关闭数据库</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">onmode -ky</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="替换liboracle-udr包"><a href="#替换liboracle-udr包" class="headerlink" title="替换liboracle.udr包"></a>替换liboracle.udr包</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cp $GBASEDBTDIR/lib/liboracle.udr $GBASEDBTDIR/lib/liboracle.backup.a2_6</span><br><span class="line">cp /opt/soft/gbase/sanxiajichang/to_char/p/liboracle.udr $GBASEDBTDIR/lib/liboracle.udr</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="替换boot1210-sql文件"><a href="#替换boot1210-sql文件" class="headerlink" title="替换boot1210.sql文件"></a>替换boot1210.sql文件</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cp $GBASEDBTDIR/etc/boot1210.sql $GBASEDBTDIR/etc/boot1210.backup.a2_6</span><br><span class="line">cp /opt/soft/gbase/sanxiajichang/to_char/p/boot1210.sql $GBASEDBTDIR/etc/boot1210.sql</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="启动数据库"><a href="#启动数据库" class="headerlink" title="启动数据库"></a>启动数据库</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">oninit -v</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="重新注册to-char函数"><a href="#重新注册to-char函数" class="headerlink" title="重新注册to_char函数"></a>重新注册to_char函数</h3><p>​		说明： 每个数据库都需要重新注册一下数据库，dbaccess连接上数据库后执行下面的sql语句就行，每个数据库逐一执行。</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">---1、修改</span></span><br><span class="line"><span class="keyword">update</span> sysprocedures <span class="keyword">set</span> mode <span class="operator">=</span> <span class="string">&#x27;D&#x27;</span> <span class="keyword">where</span> procname <span class="operator">=</span> <span class="string">&#x27;to_char&#x27;</span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">drop</span> <span class="keyword">function</span> if <span class="keyword">exists</span> gbasedbt.to_char(datetime <span class="keyword">year</span> <span class="keyword">to</span> fraction(<span class="number">5</span>),</span><br><span class="line">                                         gbasedbt.lvarchar,</span><br><span class="line">                                         gbasedbt.lvarchar);</span><br><span class="line"><span class="keyword">drop</span> <span class="keyword">function</span> if <span class="keyword">exists</span> gbasedbt.to_char(gbasedbt.decimal,</span><br><span class="line">                                         gbasedbt.lvarchar,</span><br><span class="line">                                         gbasedbt.lvarchar);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">--重新注册to_char</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">create</span> dba <span class="keyword">function</span> gbasedbt.to_char(datetime <span class="keyword">year</span> <span class="keyword">to</span> fraction(<span class="number">5</span>),</span><br><span class="line">                                     gbasedbt.lvarchar <span class="keyword">default</span> <span class="string">&#x27;YYYY-MM-DD HH24:MI:SS&#x27;</span>,</span><br><span class="line">                                     gbasedbt.lvarchar <span class="keyword">default</span> <span class="string">&#x27;&#x27;</span>)</span><br><span class="line">  returning gbasedbt.lvarchar</span><br><span class="line">  <span class="keyword">with</span> (PARALLELIZABLE,<span class="keyword">NOT</span> VARIANT,HANDLESNULLS)</span><br><span class="line">  <span class="keyword">external</span> name <span class="string">&#x27;$GBASEDBTDIR/lib/liboracle.udr(orcl_date_to_char)&#x27;</span></span><br><span class="line">  <span class="keyword">language</span> C;</span><br><span class="line"></span><br><span class="line"><span class="keyword">grant</span> <span class="keyword">execute</span> <span class="keyword">on</span> <span class="keyword">function</span> gbasedbt.to_char(datetime <span class="keyword">year</span> <span class="keyword">to</span> fraction(<span class="number">5</span>),</span><br><span class="line">                                           gbasedbt.lvarchar,</span><br><span class="line">                                           gbasedbt.lvarchar)</span><br><span class="line">  <span class="keyword">to</span> public <span class="keyword">as</span> gbasedbt;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">create</span> dba <span class="keyword">function</span> gbasedbt.to_char(gbasedbt.decimal,</span><br><span class="line">                                     gbasedbt.lvarchar,</span><br><span class="line">                                     gbasedbt.lvarchar <span class="keyword">default</span> <span class="string">&#x27;&#x27;</span>)</span><br><span class="line">  returning gbasedbt.lvarchar</span><br><span class="line">  <span class="keyword">with</span> (PARALLELIZABLE,<span class="keyword">NOT</span> VARIANT,HANDLESNULLS)</span><br><span class="line">  <span class="keyword">external</span> name <span class="string">&#x27;$GBASEDBTDIR/lib/liboracle.udr(orcl_num_to_char)&#x27;</span></span><br><span class="line">  <span class="keyword">language</span> C;</span><br><span class="line"></span><br><span class="line"><span class="keyword">grant</span> <span class="keyword">execute</span> <span class="keyword">on</span> <span class="keyword">function</span> gbasedbt.to_char(gbasedbt.decimal,</span><br><span class="line">                                           gbasedbt.lvarchar,</span><br><span class="line">                                           gbasedbt.lvarchar)</span><br><span class="line">  <span class="keyword">to</span> public <span class="keyword">as</span> gbasedbt;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">----</span></span><br><span class="line"><span class="keyword">update</span> sysprocedures <span class="keyword">set</span> mode <span class="operator">=</span> <span class="string">&#x27;d&#x27;</span> <span class="keyword">where</span> procname <span class="operator">=</span> <span class="string">&#x27;to_char&#x27;</span>;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="应用打包说明"><a href="#应用打包说明" class="headerlink" title="应用打包说明"></a>应用打包说明</h2><p>​	说明：</p>
<p>​		1、应用jdbc驱动需要使用上文描述的a2_6版。</p>
<p>​		2、应用hibernate框架需要使用上文描述的a2_6版。</p>
<p>​		3、应用url链接串如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">jdbc:gbasedbt-sqli://1.1.1.3:9088/testdb:GBASEDBTSERVER=gbase01;CLIENT_LOCALE=zh_cn.utf8;DB_LOCALE=zh_cn.utf8;IFX_LOCK_MODE_WAIT=100;DBDATE=Y4MD-;IFX_ISOLATION_LEVEL=1;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/" rel="tag">安装部署</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
    <article
  id="post-打包发布Vuenpm项目"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/05/10/%E6%89%93%E5%8C%85%E5%8F%91%E5%B8%83Vuenpm%E9%A1%B9%E7%9B%AE/"
    >打包发布Vuenpm项目</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/05/10/%E6%89%93%E5%8C%85%E5%8F%91%E5%B8%83Vuenpm%E9%A1%B9%E7%9B%AE/" class="article-date">
  <time datetime="2023-05-10T00:51:42.000Z" itemprop="datePublished">2023-05-10</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/JavaScript/">JavaScript</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h2 id="打包"><a href="#打包" class="headerlink" title="打包"></a>打包</h2><p>cd D:\VSCodeSrc\src\Vue\my-blog</p>
<p>npm run build</p>
<p>打包会生成 D:\VSCodeSrc\src\Vue\my-blog\dist 下 ： index.html文件  和  static目录。</p>
<h2 id="把Vue打包的网站上传到tomcat服务器"><a href="#把Vue打包的网站上传到tomcat服务器" class="headerlink" title="把Vue打包的网站上传到tomcat服务器"></a>把Vue打包的网站上传到tomcat服务器</h2><p>Windows:</p>
<p>​	覆盖文件：D:\VSCodeSrc\apache-tomcat-8.5.78\webapps\ROOT\index.html</p>
<p>​	覆盖目录：D:\VSCodeSrc\apache-tomcat-8.5.78\webapps\static</p>
<p>启动tomcat访问我的blog测试：</p>
<p>​	<a target="_blank" rel="noopener" href="http://www.wangwei.com:8080/">http://www.wangwei.com:8080/</a></p>
<p>Linux:</p>
<p>​	&#x2F;usr&#x2F;local&#x2F;tomcat&#x2F;apache-tomcat-8.5.82&#x2F;webapps</p>
<h2 id="Windows搭建tomcat服务"><a href="#Windows搭建tomcat服务" class="headerlink" title="Windows搭建tomcat服务"></a>Windows搭建tomcat服务</h2><p>cd D:\install\apache-tomcat-8.5.78-windows-x64\apache-tomcat-8.5.78\bin</p>
<p>startup.bat</p>
<p>说明windows把网页放到这里：D:\install\apache-tomcat-8.5.78-windows-x64\apache-tomcat-8.5.78\webapps\</p>
<h2 id="Linux搭建tomcat服务"><a href="#Linux搭建tomcat服务" class="headerlink" title="Linux搭建tomcat服务"></a>Linux搭建tomcat服务</h2><p>CentOS Linux release 7.8.2003 (Core)  </p>
<p>Linux wei3 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU&#x2F;Linux</p>
<p>下载：已经上传到百度云盘</p>
<p><a target="_blank" rel="noopener" href="https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.82/bin/apache-tomcat-8.5.82.tar.gz">https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.82/bin/apache-tomcat-8.5.82.tar.gz</a>                               </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">安装</span></span><br><span class="line">mkdir /usr/local/tomcat                 </span><br><span class="line">tar -C /usr/local/tomcat -zxvf apache-tomcat-8.5.82.tar.gz </span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">tomcat .bash_profile 环境变量</span></span><br><span class="line">TOMCAT_HOME=/usr/local/tomcat/apache-tomcat-8.5.82</span><br><span class="line">CATALINA_HOME=/usr/local/tomcat/apache-tomcat-8.5.82</span><br><span class="line">CATALINA_BASE=/usr/local/tomcat/apache-tomcat-8.5.82</span><br><span class="line">export TOMCAT_HOME CATALINA_HOME CATALINA_BASE</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">启动tomcat</span></span><br><span class="line">cd /usr/local/tomcat/apache-tomcat-8.5.82/bin</span><br><span class="line">./startup.sh</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">验证：</span></span><br><span class="line">http://1.1.1.3:8080</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">网站目录：</span></span><br><span class="line">/usr/local/tomcat/apache-tomcat-8.5.82/webapps</span><br></pre></td></tr></table></figure>



<h1 id="让tomcat支持目录访问"><a href="#让tomcat支持目录访问" class="headerlink" title="让tomcat支持目录访问"></a>让tomcat支持目录访问</h1><p> 非常简单。找到tomcat目录下conf&#x2F;web.<a target="_blank" rel="noopener" href="https://so.csdn.net/so/search?q=xml&spm=1001.2101.3001.7020">xml</a>，打开后找到如下代码 </p>
<pre><code>    &lt;init-param&gt;
        &lt;param-name&gt;listings&lt;/param-name&gt;
        &lt;param-value&gt;true&lt;/param-value&gt;
    &lt;/init-param&gt;
</code></pre>
<p> 默认情况下，listings标签下的值是false，如果想要实现上面说的功能，只需改成true即可。  </p>
<h1 id="linux-1-1-1-3-启动mysql"><a href="#linux-1-1-1-3-启动mysql" class="headerlink" title="linux 1.1.1.3 启动mysql"></a>linux 1.1.1.3 启动mysql</h1><p>[root@wei3 myblog]# systemctl stop mariadb </p>
<h1 id="如果mysql的root密码忘记："><a href="#如果mysql的root密码忘记：" class="headerlink" title="如果mysql的root密码忘记："></a>如果mysql的root密码忘记：</h1><p>在mysqld里面添加： skip-grant-tables  即可。</p>
<p>[root@wei3 myblog]# cat &#x2F;etc&#x2F;my.cnf                                                                                        </p>
<p>[mysqld]                                                                                                                   </p>
<p>datadir&#x3D;&#x2F;var&#x2F;lib&#x2F;mysql                                                                                                     </p>
<p>socket&#x3D;&#x2F;var&#x2F;lib&#x2F;mysql&#x2F;mysql.sock                                                                                                                                     </p>
<p>symbolic-links&#x3D;0                                                                                                                                                                         </p>
<p>skip-grant-tables </p>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/vue/" rel="tag">vue</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/web/" rel="tag">web</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
    <article
  id="post-测试-开启TPCC测试和HTML报告"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/05/10/%E6%B5%8B%E8%AF%95-%E5%BC%80%E5%90%AFTPCC%E6%B5%8B%E8%AF%95%E5%92%8CHTML%E6%8A%A5%E5%91%8A/"
    >测试-开启TPCC测试和HTML报告</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/05/10/%E6%B5%8B%E8%AF%95-%E5%BC%80%E5%90%AFTPCC%E6%B5%8B%E8%AF%95%E5%92%8CHTML%E6%8A%A5%E5%91%8A/" class="article-date">
  <time datetime="2023-05-10T00:47:53.000Z" itemprop="datePublished">2023-05-10</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/GBase8s/">GBase8s</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h1 id="TPCC测试"><a href="#TPCC测试" class="headerlink" title="TPCC测试"></a>TPCC测试</h1><h2 id="基础环境配置"><a href="#基础环境配置" class="headerlink" title="基础环境配置"></a>基础环境配置</h2><h3 id="java环境"><a href="#java环境" class="headerlink" title="java环境"></a>java环境</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">gbasedbt:g31[/home/gbasedbt/tpcc]$java -version</span><br><span class="line">openjdk version &quot;1.8.0_242&quot;</span><br><span class="line">OpenJDK Runtime Environment (build 1.8.0_242-b08)</span><br><span class="line">OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)</span><br></pre></td></tr></table></figure>

<h3 id="软件包"><a href="#软件包" class="headerlink" title="软件包"></a>软件包</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">D:\soft\05.工作记录\01.项目记录\00.技术\TPCC和jmeter和TPCH\tpcc\benchmark5汪伟</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">1.1.1.7 /home/gbasedbt/tpcc</span></span><br><span class="line">gbasedbt:g31[/home/gbasedbt/tpcc]$ls -l</span><br><span class="line">总用量 2304</span><br><span class="line">drwxr-xr-x. 8 gbasedbt gbasedbt     149 9月   4 2021 benchmarksql-5.0</span><br><span class="line">-rw-rw-rw-. 1 gbasedbt gbasedbt 2353486 6月  15 12:46 benchmarksql-5.0_jdk8.tar.gz</span><br><span class="line">drwxrwxr-x. 2 gbasedbt gbasedbt     123 10月 21 2021 sql.gbase_100w</span><br><span class="line">-rw-rw-rw-. 1 gbasedbt gbasedbt    3262 6月  15 12:46 sql.gbase_100w.zip</span><br><span class="line">gbasedbt:g31[/home/gbasedbt/tpcc]$</span><br></pre></td></tr></table></figure>

<h3 id="空间准备"><a href="#空间准备" class="headerlink" title="空间准备"></a>空间准备</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">DATADIR=/data/g31</span><br><span class="line">touch $&#123;DATADIR&#125;/datachk02</span><br><span class="line">touch $&#123;DATADIR&#125;/datachk03</span><br><span class="line">touch $&#123;DATADIR&#125;/datachk04</span><br><span class="line">touch $&#123;DATADIR&#125;/datachk05</span><br><span class="line">touch $&#123;DATADIR&#125;/datachk06</span><br><span class="line">touch $&#123;DATADIR&#125;/datachk07</span><br><span class="line">touch $&#123;DATADIR&#125;/datachk08</span><br><span class="line">touch $&#123;DATADIR&#125;/datachk09</span><br><span class="line">touch $&#123;DATADIR&#125;/datachk10</span><br><span class="line">chmod 660 $&#123;DATADIR&#125;/datachk02</span><br><span class="line">chmod 660 $&#123;DATADIR&#125;/datachk03</span><br><span class="line">chmod 660 $&#123;DATADIR&#125;/datachk04</span><br><span class="line">chmod 660 $&#123;DATADIR&#125;/datachk05</span><br><span class="line">chmod 660 $&#123;DATADIR&#125;/datachk06</span><br><span class="line">chmod 660 $&#123;DATADIR&#125;/datachk07</span><br><span class="line">chmod 660 $&#123;DATADIR&#125;/datachk08</span><br><span class="line">chmod 660 $&#123;DATADIR&#125;/datachk09</span><br><span class="line">chmod 660 $&#123;DATADIR&#125;/datachk10</span><br><span class="line">onspaces  -c -d datadbs02 -p $&#123;DATADIR&#125;/datachk02 -o 0 -s 1024000  -k 16</span><br><span class="line">onspaces  -c -d datadbs03 -p $&#123;DATADIR&#125;/datachk03 -o 0 -s 1024000  -k 16</span><br><span class="line">onspaces  -c -d datadbs04 -p $&#123;DATADIR&#125;/datachk04 -o 0 -s 1024000  -k 16</span><br><span class="line">onspaces  -c -d datadbs05 -p $&#123;DATADIR&#125;/datachk05 -o 0 -s 1024000  -k 16</span><br><span class="line">onspaces  -c -d datadbs06 -p $&#123;DATADIR&#125;/datachk06 -o 0 -s 1024000  -k 16</span><br><span class="line">onspaces  -c -d datadbs07 -p $&#123;DATADIR&#125;/datachk07 -o 0 -s 1024000  -k 16</span><br><span class="line">onspaces  -c -d datadbs08 -p $&#123;DATADIR&#125;/datachk08 -o 0 -s 1024000  -k 16</span><br><span class="line">onspaces  -c -d datadbs09 -p $&#123;DATADIR&#125;/datachk09 -o 0 -s 1024000  -k 16</span><br><span class="line">onspaces  -c -d datadbs10 -p $&#123;DATADIR&#125;/datachk10 -o 0 -s 1024000  -k 16</span><br></pre></td></tr></table></figure>

<h3 id="建库"><a href="#建库" class="headerlink" title="建库"></a>建库</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">dbaccess sysmaster <span class="operator">&lt;&lt;</span><span class="operator">!</span></span><br><span class="line"><span class="keyword">drop</span> database if <span class="keyword">exists</span> tpcc;</span><br><span class="line"><span class="keyword">create</span> database tpcc <span class="keyword">in</span> datadbs01 <span class="keyword">with</span> log;</span><br><span class="line"><span class="operator">!</span></span><br></pre></td></tr></table></figure>

<h3 id="建表"><a href="#建表" class="headerlink" title="建表"></a>建表</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">cd <span class="operator">/</span>home<span class="operator">/</span>gbasedbt<span class="operator">/</span>tpcc<span class="operator">/</span>sql.gbase_100w</span><br><span class="line">dbaccess tpcc tableCreates.sql</span><br><span class="line">dbaccess tpcc indexCreates.sql</span><br><span class="line">dbaccess tpcc foreignKeys.sql</span><br><span class="line">dbaccess tpcc extraHistID.sql</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="统计更新"><a href="#统计更新" class="headerlink" title="统计更新"></a>统计更新</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dbaccess tpcc buildFinish.sql</span><br></pre></td></tr></table></figure>



<h2 id="TPCC软件配置"><a href="#TPCC软件配置" class="headerlink" title="TPCC软件配置"></a>TPCC软件配置</h2><h3 id="添加驱动"><a href="#添加驱动" class="headerlink" title="添加驱动"></a>添加驱动</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">上传 D:\jdbc\gbase\gbasedbtjdbc_3.3.0_2_36477d.jar</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">到</span> </span><br><span class="line">/home/gbasedbt/tpcc/benchmarksql-5.0/lib/gbase/</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">目录下</span></span><br></pre></td></tr></table></figure>

<h3 id="run-x2F-props-gbase"><a href="#run-x2F-props-gbase" class="headerlink" title="run&#x2F;props.gbase"></a>run&#x2F;props.gbase</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">cd /home/gbasedbt/tpcc/benchmarksql-5.0/run</span><br><span class="line">cat &gt; props.gbase &lt;&lt;EOF</span><br><span class="line">db=gbase</span><br><span class="line">driver=com.gbasedbt.jdbc.Driver</span><br><span class="line">conn=jdbc:gbasedbt-sqli://1.1.1.3:60111/tpcc:GBASEDBTSERVER=g31;DB_LOCALE=zh_CN.utf8;CLIENT_LOCALE=zh_CN.utf8;IFX_LOCK_MODE_WAIT=60;IFX_ISOLATION_LEVEL=1U;OPTOFC=1;</span><br><span class="line">user=gbasedbt</span><br><span class="line">password=GBase123</span><br><span class="line"></span><br><span class="line">warehouses=10</span><br><span class="line">loadWorkers=2</span><br><span class="line"></span><br><span class="line">terminals=100</span><br><span class="line">//To run specified transactions per terminal- runMins must equal zero</span><br><span class="line">runTxnsPerTerminal=0</span><br><span class="line">//To run for specified minutes- runTxnsPerTerminal must equal zero</span><br><span class="line">runMins=2</span><br><span class="line">//Number of total transactions per minute</span><br><span class="line">limitTxnsPerMin=0</span><br><span class="line"></span><br><span class="line">//Set to true to run in 4.x compatible mode. Set to false to use the</span><br><span class="line">//entire configured database evenly.</span><br><span class="line">terminalWarehouseFixed=true</span><br><span class="line"></span><br><span class="line">//The following five values must add up to 100</span><br><span class="line">newOrderWeight=45</span><br><span class="line">paymentWeight=43</span><br><span class="line">orderStatusWeight=4</span><br><span class="line">deliveryWeight=4</span><br><span class="line">stockLevelWeight=4</span><br><span class="line"></span><br><span class="line">// Directory name to create for collecting detailed result data.</span><br><span class="line">// Comment this out to suppress.</span><br><span class="line">resultDirectory=my_result_%tY-%tm-%td_%tH%tM%tS</span><br><span class="line">osCollectorScript=./misc/os_collector_linux.py</span><br><span class="line">osCollectorInterval=1</span><br><span class="line">osCollectorSSHAddr=root@1.1.1.3</span><br><span class="line">osCollectorDevices=net_ens33 blk_sda</span><br><span class="line">EOF</span><br></pre></td></tr></table></figure>



<h3 id="灌数"><a href="#灌数" class="headerlink" title="灌数"></a>灌数</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd <span class="operator">/</span>home<span class="operator">/</span>gbasedbt<span class="operator">/</span>tpcc<span class="operator">/</span>benchmarksql<span class="number">-5.0</span><span class="operator">/</span>run</span><br><span class="line">.<span class="operator">/</span>runLoader.sh props.gbase</span><br><span class="line"></span><br></pre></td></tr></table></figure>





<h2 id="TPCC开启测试–第一次"><a href="#TPCC开启测试–第一次" class="headerlink" title="TPCC开启测试–第一次"></a>TPCC开启测试–第一次</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd /home/gbasedbt/tpcc/benchmarksql-5.0/run</span><br><span class="line">./runBenchmark.sh props.gbase</span><br><span class="line"></span><br></pre></td></tr></table></figure>





<h2 id="TPCC测试结果汇录"><a href="#TPCC测试结果汇录" class="headerlink" title="TPCC测试结果汇录"></a>TPCC测试结果汇录</h2><p>​	正常10万，加强50万。</p>
<table>
<thead>
<tr>
<th></th>
<th>CPU分配</th>
<th>TPCC仓库数量</th>
<th>终端数量</th>
<th>测试结果：TPMC</th>
<th>压测时CPU使用率</th>
</tr>
</thead>
<tbody><tr>
<td>物理机</td>
<td>96</td>
<td>100</td>
<td>400</td>
<td>46.97万</td>
<td>64%</td>
</tr>
<tr>
<td>虚拟机</td>
<td>8</td>
<td>10</td>
<td>40</td>
<td>13.95万</td>
<td>81%</td>
</tr>
</tbody></table>
<h2 id="TPCC开启测试-–-第2次-带html输出"><a href="#TPCC开启测试-–-第2次-带html输出" class="headerlink" title="TPCC开启测试 – 第2次 带html输出"></a>TPCC开启测试 – 第2次 带html输出</h2><p>benchmarksql 除了提供文字版输出, 还有 通过工具生成 html版本的报告 ，不过需要安装R语言和提前配置</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">cd /home/gbasedbt/tpcc/benchmarksql-5.0/run</span><br><span class="line">resultDirectory=$(date &#x27;+%Y%m%d-%H%M%S&#x27;) </span><br><span class="line">./runBenchmark.sh props.gbase</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">压测结束之后，使用命令</span></span><br><span class="line">sh generateReport.sh  $resultDirectory</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>这时发现，原来的bm5没有结果目录生成。</p>
<p>重新下载一个bm5看看：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">2.1 下载和编译</span><br><span class="line">    #从github 直接下载源码进行编译安装</span><br><span class="line">    mkdir /home/gbasedbt/tpcc/bm5Download</span><br><span class="line">    cd /home/gbasedbt/tpcc/bm5Download</span><br><span class="line">    git clone https://github.com/petergeoghegan/benchmarksql</span><br><span class="line">    #安装ant 编译工具</span><br><span class="line">    yum install -y ant</span><br><span class="line">    #修改源码添加对gbase支持</span><br><span class="line">    src/client/jTPCCConfig.java</span><br><span class="line">    	DB_GBASEDBT = 4;</span><br><span class="line">    src/client/jTPCC.java</span><br><span class="line">    	else if (iDB.equals(&quot;gbase&quot;))</span><br><span class="line">        dbType = DB_GBASEDBT;  	</span><br><span class="line">    #编译</span><br><span class="line">    cd /home/gbasedbt/tpcc/bm5Download/benchmarksql</span><br><span class="line">    ant</span><br><span class="line">还有一种是直接从官网下载zip安装包，直接解压缩即可。</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>可以再次测了：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">对新下载的benchmarksql做配置：</span></span><br><span class="line">cd /home/gbasedbt/tpcc/bm5Download/benchmarksql/run</span><br><span class="line">cp /home/gbasedbt/tpcc/benchmarksql-5.0/run/props.gbase ./</span><br><span class="line">mkdir /home/gbasedbt/tpcc/bm5Download/benchmarksql/lib/gbase/</span><br><span class="line">cp /home/gbasedbt/tpcc/benchmarksql-5.0/lib/gbase/gbasedbtjdbc_3.3.0_2_36477d.jar /home/gbasedbt/tpcc/bm5Download/benchmarksql/lib/gbase/</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">加载gbase驱动：</span></span><br><span class="line">vi /home/gbasedbt/tpcc/bm5Download/benchmarksql/run/funcs.sh </span><br><span class="line"> 修改1：</span><br><span class="line">        gbase)</span><br><span class="line">            cp=&quot;../lib/gbase/*:../lib/*&quot;</span><br><span class="line">            ;;</span><br><span class="line"> 修改2：</span><br><span class="line">	firebird|oracle|postgres|gbase)</span><br><span class="line">	</span><br><span class="line">vi /home/gbasedbt/tpcc/bm5Download/benchmarksql/run/props.gbase</span><br><span class="line"> 去掉注释：</span><br><span class="line">	resultDirectory=my_result_%tY-%tm-%td_%tH%tM%tS</span><br><span class="line"><span class="meta prompt_"> </span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">开始测试：</span></span><br><span class="line">cd /home/gbasedbt/tpcc/bm5Download/benchmarksql/run    </span><br><span class="line">./runBenchmark.sh props.gbase</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">压测结束之后，使用命令</span></span><br><span class="line">sh generateReport.sh  my_result_2022-08-24_114532</span><br><span class="line"></span><br></pre></td></tr></table></figure>





<p>这个报错要么是python脚本的os不匹配，要么是要收集的设备名字写错了：</p>
<p>12:45:05,551 [Thread-0] ERROR  OSCollector$CollectData : OSCollector, unexpected EOF while reading from external helper process </p>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/tpcc/" rel="tag">tpcc</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%B5%8B%E8%AF%95/" rel="tag">测试</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
  </article>
  

  
  <nav class="page-nav">
    
    <a class="extend prev" rel="prev" href="/page/3/">上一页</a><a class="page-number" href="/">1</a><a class="page-number" href="/page/2/">2</a><a class="page-number" href="/page/3/">3</a><span class="page-number current">4</span><a class="page-number" href="/page/5/">5</a><a class="page-number" href="/page/6/">6</a><a class="extend next" rel="next" href="/page/5/">下一页</a>
  </nav>
  
</section>
</div>

      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2023-2024
        <i class="ri-heart-fill heart_icon"></i> Wang Wei
      </li>
    </ul>
    <ul>
      <li>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>Visitors:<span id="busuanzi_value_site_uv"></span></span>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>Views:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
      </li>
    </ul>
  </div>
</footer>    
    </main>
    <div class="float_btns">
      <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

    </div>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ww.ico" alt="朝花夕拾"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-3.6.0.min.js"></script>
 
<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->

<script src="https://cdn.staticfile.org/jquery-modal/0.9.2/jquery.modal.min.js"></script>
<link
  rel="stylesheet"
  href="https://cdn.staticfile.org/jquery-modal/0.9.2/jquery.modal.min.css"
/>
<script src="https://cdn.staticfile.org/justifiedGallery/3.8.1/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->
 
<script src="/js/busuanzi-2.3.pure.min.js"></script>
 
<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->
 
<link rel="stylesheet" href="/css/clipboard.css">
 <script src="https://cdn.staticfile.org/clipboard.js/2.0.10/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>
 
<!-- CanvasBackground -->

<script>
  if (window.mermaid) {
    mermaid.initialize({ theme: "forest" });
  }
</script>


    
    

  </div>
</body>

</html>